Asking users to subscribe to your emails on the checkout page is the perfect place to begin remarketing your store and products to advocates. A paying customer doesn’t need as much convincing to buy a product if they’ve already done it before, so by contacting them by email, your chances of turning them into another sale are far greater. This quick guide shows you how you can get users to opt-in to emails on the checkout page without an intrusive popup which we see far too often. If a user does subscribe and checkout, you’ll see in the order editor that the meta will be updated to show whether they have subscribed (checked the box) or not.
/**
* Snippet Name: Add a custom email subscription checkbox field to the WooCommerce checkout form.
* Snippet Author: ecommercehints.com
*/
add_action( 'woocommerce_after_order_notes', 'ecommercehints_custom_email_subscription_checkbox_field' );
add_action( 'woocommerce_checkout_update_order_meta', 'ecommercehints_save_subscription_input' );
function ecommercehints_custom_email_subscription_checkbox_field( $checkout ) {
woocommerce_form_field( 'subscribed', array(
'type' => 'checkbox',
'class' => array('form-row-wide'),
'label' => 'Subscribe To Emails?',
), $checkout->get_value( 'subscribed' ) );
}
function ecommercehints_save_subscription_input( $order_id ){
if( !empty( $_POST['subscribed'] ) && $_POST['subscribed'] == 1 ) {
update_post_meta( $order_id, 'subscribed', Yes );
} else {
update_post_meta( $order_id, 'subscribed', No );
}
}
How to see if a customer subscribed?
Simply head to the order editor in the dasboard and scroll down to where the order meta is shown, as displayed in this image:
