-
Notifications
You must be signed in to change notification settings - Fork 67
Filter on newsletter field
Welcome to the guide on Filtering the Newsletter Field in the MailChimp for WooCommerce Integration. This guide will help you understand how to create a function that controls the HTML for the checkbox found on the checkout page.
This option allows developers to create a function that controls the HTML for the checkbox found on the checkout page. The function is purely cosmetic. Developers may create an override PHP file placed in their theme's directory. This allows them to edit or add HTML and change the 'priority' for when the function gets loaded; along with the proper WooCommerce event to render in the location on the page of their choice.
There are 2 general steps necessary for this feature to be enabled:
- Creating a custom overriding function that contains code that will be used for data morphing.
- Add a filter with the newly created function with the same name in it. This allows the plugin to call the filter and run through the override.
Here's an example of how to create a custom function for the checkout page:
function mailchimp_filter_for_checkout_field ($checkbox_html, $status, $label) {
$new_label = "Would you like to subscribe to our newsletter, please and thank you?";
return str_ireplace( $label, $new_label, $checkbox_html );
}
add_filter('mailchimp_woocommerce_newsletter_field', 'mailchimp_filter_for_checkout_field', 10, 3);
When a customer has an account, visiting their profile, you can render a new label, or you can even alter the returned HTML to display.
function mailchimp_filter_for_my_account_field ($mailchimp_my_account_html, $mailchimp_user_subscription_status) {
$mailchimp_my_account_html= 'edit radio buttons html here'; // default html file is under mc-woocommerce/public/partials/mailchimp-woocommerce-my-account.php
return $mailchimp_my_account_html;
}
add_filter('mailchimp_woocommerce_my_account_field', 'mailchimp_filter_for_my_account_field', 10, 2);
As a store owner, you have the ability to subscribe or mark your customers as transactional directly from the profile page in your Wordpress admin. This is convenient for store owners that might be troubleshooting subscriber status on a particular customer, or group of customers.