• Resolved multimediaarts

    (@multimediaarts)


    I downloaded your plugin and it seems to work fine, except for the fact that my subscribers are receiving double opt-in when signing up via woo commerce or contact form 7. I have literally spent hours on your support forums with no luck at all.

    The closest thread I found was this: https://www.ads-software.com/support/topic/single-opt-in-on-contact-form-7/

    But it does not provide a solution at all. The plugin I had before was “MailChimp for Woocommerce” and that one does single opt-in right from the checkout screen.

    Furthermore, in any case we were to stick with the double opt-in, there’s no option to override the subscriber’s group with the new one. It instead adds the subscriber in both groups. I can see that option from your form builder, but not for the woocommerce or contact form 7.

    Ideal objective: Clients that sign up to purchase a service and wish to receive emails may opt in via a checkbox during checkout and will be added to the “active” group. However, let’s say they stop using the service, so they request a cancellation via a contact form 7 and they get added to the “inactive” group. All members in both groups would be able to unsubscribe at any time by clicking the unsubscribe button at the bottom of each email.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Freddie

    (@fmixell)

    @multimediaarts,

    This is possible but its not always recommended because Mailchimp is not a huge fan of single opt-in.

    However, if you’d like to do this you can use the following function to filter the forms and opt those users in.

    
    add_filter( 'yikes-mailchimp-checkbox-integration-body', 'set_integrations_to_single_optin', 10, 4 );
    function set_integrations_to_single_optin( $request_body, $integration_type, $list_id, $additional_vars ) {
    	$request_body['status_if_new'] = 'subscribed';
    	$request_body['status']        = 'subscribed';
    
    	return $request_body;
    }
    

    This code should be added to the functions.php file in your Child Theme. If you’re not sure what that is, you can add custom functions with this plugin.

    https://www.ads-software.com/plugins/my-custom-functions/

    Hope that helps you out!

    Cheers,

    Freddie

    • This reply was modified 5 years, 7 months ago by Freddie.
    Thread Starter multimediaarts

    (@multimediaarts)

    Awesome! That did the trick!

    The only thing now is that it doesn’t remove the user from the other group the member was in. For example, if the user signs up via woo commerce: they’re added to Group 1. However, if the member decides to fill out the contact form, they get added to Group 2. I need them to only be signed up to either Group 1 or Group 2.

    I know it’s doable within the form builder of the plugin under the Submission Settings by choosing the option “Replace: Replace all interest groups with the new ones submitted.”

    How can we have this enabled for the integration settings for WooCommerce and Contact Form?

    Plugin Contributor Freddie

    (@fmixell)

    @multimediaarts,

    If you would like to change the interest groups this might suit your needs here. As you can see you have the ability to filter out the interest groups.

    You also have the ability to create conditionals to change interest groups based on Contact Form 7 or Woo. I’ve commented those out but if you want to change the interest groups based on one of those form types you have the ability.

    Let me know if this works out for you or if you need any help modifying it for your needs.

    
    add_filter( 'yikes-mailchimp-checkbox-integration-body', 'yikes_mailchimp_optin_interest_group_checkboxes', 10, 4 );
    
    function yikes_mailchimp_optin_interest_group_checkboxes( $request_body, $integration_type, $list_id, $additional_vars ) {
    
    	// Use $intergration_type to check for 
            // cf7: if ( 'contact_form_7' === $intergration_type ) {  }
            // woo: if ( 'woocommerce_checkout_form' === $intergration_type ) {  }
    
    	// Interest group one.
    	$group_one = '9dc56695e6';
    
            // Interest group two.
    	$group_two = '5ed969c566';
    
            // Check for first interest group 
            if ( false === $request_body['interests'][ $group_one ] ) {
                $request_body['interests'][ $group_one ] = true;
            }
    
            // Check for second interest group
            if ( true === $request_body['interests'][ $group_two ] ) {
                 $request_body['interests'][ $group_two ] = false;
            }
    
    	return $request_body;
    }
    
    • This reply was modified 5 years, 7 months ago by Freddie.
    • This reply was modified 5 years, 7 months ago by Freddie.
    Plugin Contributor Freddie

    (@fmixell)

    Here’s another function you might find useful as well. Here you’ll see that we’re checking for Woo and changing the interest groups based on individual products.

    
    add_filter( 'yikes-mailchimp-checkbox-integration-body', 'yikes_mailchimp_optin_interest_group_by_product', 10, 4 );
    
    function yikes_mailchimp_optin_interest_group_by_product( $request_body, $integration_type, $list_id, $additional_vars ) {
    
    	if ( $integration_type !== 'woocommerce_checkout_form' || ! isset( $additional_vars['order'] ) || ! empty( $additional_vars['order'] ) && ! is_object( $additional_vars['order'] ) ) {
    		return $request_body;
    	}
    
    	// Get the products in the order. This is built with the constraint that there is one item per order.
    	$order_item  = current( $additional_vars['order']->get_items() );
    	$product_id  = $order_item->get_product_id();
    	$mc_group_id = '';
    
    	switch( (int) $product_id ) {
    		case 16640:
    			$mc_group_id = '9dc56695e6';
    		break;
    	}
    
    	if ( ! empty( $mc_group_id ) ) {
    		$request_body['interests'][ $mc_group_id ] = true;
    	}
    
    	return $request_body;
    }
    
    • This reply was modified 5 years, 7 months ago by Freddie.
    Plugin Contributor Freddie

    (@fmixell)

    One final note, you could combine all this functionality into one function because you’re hitting the same filter both times.

    add_filter( 'yikes-mailchimp-checkbox-integration-body', 'yikes_mailchimp_optin_filtered', 10, 4 );
    
    function yikes_mailchimp_optin_filtered( $request_body, $integration_type, $list_id, $additional_vars ) {
    
        $request_body['status_if_new'] = 'subscribed';
        $request_body['status']        = 'subscribed';
    
        // Use $intergration_type to check for 
        // cf7: if ( 'contact_form_7' === $intergration_type ) {  }
        // woo: if ( 'woocommerce_checkout_form' === $intergration_type ) {  }
    
    	// Interest group one.
        $group_one = '9dc56695e6';
    
        // Interest group two.
        $group_two = '5ed969c566';
    
        // Check for first interest group 
        if ( false === $request_body['interests'][ $group_one ] ) {
           $request_body['interests'][ $group_one ] = true;
        }
    
        // Check for second interest group
        if ( true === $request_body['interests'][ $group_two ] ) {
             $request_body['interests'][ $group_two ] = false;
        }
    
        return $request_body;
    
    }
    Thread Starter multimediaarts

    (@multimediaarts)

    Hello Freddie, thank you so much for replying. I believe we’re getting close! I can follow along with your code except for one thing, how does Woo or cf7 override the group?

    Basically, Woo is used to enroll subscribers into the group called “active”. And Cf7 is used to enroll subscribers into the group called “inactive”. Currently, If I am in the “active” group and I use cf7 to be in the “inactive” group, I will be in both “active” and “inactive”. Same thing vice versa, let’s say I am currently in group “inactive” and I use Woo to join the “active” group, but I don’t get removed from the “inactive” group and end up in both at the same time.

    The ideal thing would be for Woo to only enroll subscribers to the “active” group and remove from any other group the subscriber was previously in. The ideal thing for Cf7 would be to only enroll subscribers to the “inactive” group.

    in example:

    if ( ‘contact_form_7’ === $intergration_type ) { The only group the subscriber should be in is the group called “inactive” remove from “active” }
    if ( ‘woocommerce_checkout_form’ === $intergration_type ) { The only group the subscriber should be in is the group called “active” remove from “inactive” }

    Plugin Contributor Freddie

    (@fmixell)

    This should do the trick for you but you’ll still need to figure out the ID’s for the interest groups. If you look at them on mailchimp you can see them in the URL.

    Let me know if this works out for you!

    – Freddie

    
    add_filter( 'yikes-mailchimp-checkbox-integration-body', 'yikes_mailchimp_optin_filtered', 10, 4 );
    
    function yikes_mailchimp_optin_filtered( $request_body, $integration_type, $list_id, $additional_vars ) {
    
        $request_body['status_if_new'] = 'subscribed';
        $request_body['status']        = 'subscribed';
    
        // Interest groups.
        $active   = '9dc56695e6';
        $inactive = '5ed969c566';
    
        // Use $intergration_type to check for 
        if ( 'contact_form_7' === $intergration_type ) {
            $request_body['interests'][$active]   = false;
            $request_body['interests'][$inactive] = true;
        }
    
        if ( 'woocommerce_checkout_form' === $intergration_type ) {
            $request_body['interests'][$active]   = true;
            $request_body['interests'][$inactive] = false;
        }
    
        return $request_body;
    
    }
    
    Thread Starter multimediaarts

    (@multimediaarts)

    Hello Freddie,

    It looks like the code is only working for the opt-in part, but not for adding them to the groups. I located the group ID from the URL but it was too short (only 5 digits), so I was able to locate it from the Mailchimp API Playground and I obtained the ID’s for both groups (Active & Inactive). This is the forum that helped me obtain those ID’s: https://stackoverflow.com/questions/33204839/how-can-i-get-interest-groups-from-the-mailchimp-3-0-api

    I added the group ID’s and it’s not working (I also tried with the ID’s from the URL and no luck). But I know for a fact it’s reading the code because it’s not doing the double opt-in anymore, which is great. But it’s not adding them on their respective groups.

    I feel like we’re close, what do you think it could be?

    Thread Starter multimediaarts

    (@multimediaarts)

    FIXED!!!

    Freddie, your code was correct! The only thing it had was the word “integration” was mispelled as “intergration”.

    So for anybody else looking for this solution, I obtained the group ID’s from this website: https://stackoverflow.com/questions/33204839/how-can-i-get-interest-groups-from-the-mailchimp-3-0-api

    and the code I used is below:

    add_filter( 'yikes-mailchimp-checkbox-integration-body', 'yikes_mailchimp_optin_filtered', 10, 4 );
    
    function yikes_mailchimp_optin_filtered( $request_body, $integration_type, $list_id, $additional_vars ) {
    
        $request_body['status_if_new'] = 'subscribed';
        $request_body['status']        = 'subscribed';
    
        // Interest groups.
        $active   = '9dc56695e6';
        $inactive = '5ed969c566';
    
        // Use $intergration_type to check for 
        if ( 'contact_form_7' === $integration_type ) {
            $request_body['interests'][$active]   = false;
            $request_body['interests'][$inactive] = true;
        }
    
        if ( 'woocommerce_checkout_form' === $integration_type ) {
            $request_body['interests'][$active]   = true;
            $request_body['interests'][$inactive] = false;
        }
    
        return $request_body;
    
    }

    Thank you very much for your help Freddie!

    Plugin Contributor Freddie

    (@fmixell)

    @multimediaarts,

    I’m glad this was resolved for you! If you have any more questions just open another thread on the forum and I’d be happy to help.

    Also, thanks for pointing out the typo I’m going to fix it above in case anyone finds this answer googling and copies it!

    Cheers,

    Freddie

    Thread Starter multimediaarts

    (@multimediaarts)

    Hello Freddie,

    I ran into another situation with the plugin in regards to this solution listed here. The opt-in checkbox seems to be disabled when customers log-in during checkout and proceed with the payment.

    This is bad for us because when people sign up, they get subscribed into a group called “Active Members” in Mailchimp. When they fill out the cancellation form via a Contact Form 7 submission, they get subscribed into a group called “inactive members” which is great! However, if the same person comes back and signs up, they remain in the “inactive members” group because the opt-in checkbox is no longer there because he’s a returning customer. How can we enable the opt-in checkbox at all times during checkout?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Single Opt-in on WooCommerce’ is closed to new replies.