Zum Inhalt springen

Usage

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

This page follows one opt-in end to end, a customer ticks the box at checkout, the record is stored, you review and export it, and documents the single developer action for add-ons.

When the opt-in is enabled, Subscribe renders a consent row on the classic checkout, after the terms-and-conditions area, unticked unless you set it to start ticked. The row is the affordance: an email-stamp checkbox, the consent label, and a postmark mark that “lands” beside the label when the box is franked. The only script is presentation, it toggles a class for the postmark animation. WooCommerce owns the form and the submit; with JavaScript off the checkbox and its inked checkmark still work, only the postmark flourish is skipped.

Subscribe records the subscriber on woocommerce_checkout_order_processed, which fires after a successful classic checkout. It only acts when its own field (subscribe_optin) was posted with the value 1, i.e. the box was ticked. WooCommerce has already verified the checkout nonce by this point, so Subscribe just reads its own already-validated field.

The email comes from the order’s billing email; if the order object is unavailable, it falls back to the posted billing_email, validated with is_email(). An invalid or empty email is skipped silently.

Before storing, Subscribe checks whether the email already exists, a case-insensitive lookup on the _subscribe_email meta against published and private records. If it does, nothing happens; you never get a duplicate from a repeat customer. A genuinely new email is stored as a private subscribe_subscriber post with four meta values:

  • _subscribe_email, the sanitised email (also the post title)
  • _subscribe_consent, 1, the explicit consent flag
  • _subscribe_source, checkout
  • _subscribe_consented_at, the Unix timestamp of the opt-in

Open WooCommerce → Subscribers. The list shows Email (a mailto: link), Source (e.g. Checkout) and Subscribed (the date, sortable). Open a record for the Subscriber details meta box, which shows the email, whether explicit consent was recorded, the source and the subscribed-at date. New records cannot be created from the admin UI, subscribers only enter through a real opt-in.

The Export to CSV button sits above the Subscribers list. It streams every subscriber as subscribers-YYYY-MM-DD.csv with four columns: Email, Consent (Yes/No), Source and Subscribed at (UTC, Y-m-d H:i:s). The download link is nonce-protected and limited to manage_woocommerce. Cells beginning with =, +, -, @, tab or carriage return are prefixed with a single quote so a subscriber-supplied value can never execute as a spreadsheet formula (OWASP CSV-injection mitigation), and every field is RFC 4180 quote-wrapped.

Subscribe sends nothing to an external service, export the CSV and import it into your email tool when you are ready.

For developers: subscribe/subscriber_created

Section titled “For developers: subscribe/subscriber_created”

A new subscriber fires one action. It runs only for genuinely new opt-ins, the de-duplication above guarantees it never fires for an existing email.

add_action(
'subscribe/subscriber_created',
function ( int $post_id, string $email, string $source ): void {
// e.g. send a welcome email, log the signup, or push to your own queue.
wp_mail(
$email,
__( 'Thanks for subscribing', 'your-textdomain' ),
sprintf( "You're on the list (%s).", $source )
);
},
10,
3
);

This is the supported extension point, a welcome email, an internal admin notification, or a sync to your own system all hang off it. (The plugin also fires an internal boot signal for add-ons to extend its container; that is not part of the public surface and you should not depend on it for reacting to opt-ins.)

The checkbox is a real <input type="checkbox"> inside a <label>, so the whole row is clickable and screen-reader-labelled. Focus shows a visible :focus-visible outline. The postmark space is reserved at all times (toggled via opacity, never display), so the row never reflows when it animates, no layout shift. The franking animation is dropped under prefers-reduced-motion: reduce, and the colours have light- and dark-scheme values chosen to meet WCAG AA contrast. CSS and the small presentation script load only on the checkout, in the footer.