Support » Plugin: WP WooCommerce Mailchimp » Checkbox field is duplicated at each Ajax update on checkout page

  • Resolved frafor

    (@frafor)


    Hi There!

    Very nice and effective plugin, with seamless integration!

    I’ve noticed a bug. I’m working on a barebone theme based on _s with very little customization for Woocommerce, meaning that most of the job is done by woocommerce’s embedded templates with few action/filter overrides.

    I noticed that anytime the checkout page generates an Ajax request (for the payment / order review sections), then the checkbox is cloned just below its position.

    The woocommerce hooks that are affected by this particular behaviour (which is not only related to your plugin) are all the “woocommerce_review_order_* series.

    I suggest you to add the woocommerce_checkout_order_review hook with a priority of 11, or higher than 10 on the “Opt-In Checkbox Location” list of the plugin’s option page. I’ve found this hook is not involved in Ajax updates, and does not generate clones!

    • This topic was modified 1 year ago by frafor.
    • This topic was modified 1 year ago by frafor.
    • This topic was modified 1 year ago by frafor.
    • This topic was modified 1 year ago by frafor.
Viewing 4 replies - 1 through 4 (of 4 total)
  • frafor

    (@frafor)

    For those interested in the issue, I’ve managed to add the hook via a filter in this way (which makes possible to add the checkbox almost where you want):

    
    /** Add hook to Mailchimp Woocommerce position list **/
    
    function add_hook_mcwc($settings) {
    	
    	foreach($settings as &$section) {
    		if($section['id'] == 'ss_wc_mailchimp_opt_in_checkbox_display_location') {
    			$section['options']['woocommerce_checkout_order_review'] = __( 'Woocommerce_checkout_order_review Hook', 'woocommerce-mailchimp' );
    		}
    	}
    	
    	return $settings;
    	
    }
    add_filter('ss_wc_mailchimp_settings_general', 'add_hook_mcwc', 100);

    However, to change priority it’s needed to manually edit the file class-ss-wc-mailchimp-handler.php on line 85 by adding the desired priority:

    add_action( $opt_in_checkbox_display_location, array( $this, 'maybe_add_checkout_fields' ), 12 );

    It would be cool if the devs of the plugin could add a filter there to edit the priority value. In this way there’s no need to edit plugin files (which we know it’s always baaaad. Very bad!)

    • This reply was modified 1 year ago by frafor. Reason: baaaad
    Plugin Author Saint Systems

    (@saintsystems)

    @frafor Thanks for posting this issue and a suggested fix. You can also switch to the checkbox location titled “Order review above cart/product table” which hooks into the woocommerce_checkout_before_order_review hook.

    We will either be removing the other hooks in a future update or will consider your suggested fix. There is a Github issue on WooCommerce where they comment on this issue and advise against its use for this. I’ll locate that and post it here for reference.

    frafor

    (@frafor)

    Thanks for your reply. The main issue to me is the default priority setting: there should be a way to change it. Otherwise it’s not possible to control the position of the checkbox on themes that edit Woocommerce templates via hooks!

    Hi, After last updated I obviously lost the changes, so I figured out this way to create a customized action at a prioritized point within woocommerce_checkout_order_review. Sort of action inception, but it works withouth the need to modify the plugin file.

    function add_hook_mcwc($settings) {
    	
    	foreach($settings as &$section) {
    		if($section['id'] == 'ss_wc_mailchimp_opt_in_checkbox_display_location') {
    			$section['options']['woocommerce_checkout_order_review_p12'] = __( 'Woocommerce_checkout_order_review p12 Hook', 'woocommerce-mailchimp' );
    		}
    	}
    	
    	return $settings;
    	
    }
    add_filter('ss_wc_mailchimp_settings_general', 'add_hook_mcwc', 100);
    
    function add_prioritized_hook_mcwc() {
    	do_action('woocommerce_checkout_order_review_p12');
    }
    add_action('woocommerce_checkout_order_review', 'add_prioritized_hook_mcwc', 12);
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Checkbox field is duplicated at each Ajax update on checkout page’ is closed to new replies.