Skip to content

Filter on newsletter field

khungate edited this page Jul 25, 2023 · 7 revisions

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.

Overview

Purpose of the Option

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.

Implementation

Steps

There are 2 general steps necessary for this feature to be enabled:

  1. Creating a custom overriding function that contains code that will be used for data morphing.
  2. 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.

Checkout Page Hook

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);

My Account Page Hook

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);

Admin Overrides

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.