Support » Plugin: Variation Swatches for WooCommerce » Fixed: Add Product Bundle Support

  • Philipp

    (@philippmuenchen)


    Hi there,
    as I wanted to use the plugin with the WC Product Bundle plugin I debuged an issue that caused the JS running twice per veriable product form in such bundled products.

    In your plugins frontend.js can you please add the following to line 11 right after setting $form as a constant:

    
    			if( $form.hasClass('swatches-support')) {
    				return;
    			}
    

    That goes sure that the JS only runs on forms that are not already initialized.

    Kind regards,

    Philipp

Viewing 4 replies - 1 through 4 (of 4 total)
  • Dash Commerce

    (@dashcommerce)

    Hi Philipp!

    How did you initialize the $form constant?

    I should put this code on line 11 of the file woo-variation-swatches/assets/js/frontend.js, right?

    We are using the woo-variation-swatches plugin version 1.0.80.

    Many Thanks!

    Philipp

    (@philippmuenchen)

    It should just stop executing the script if the $form element is already there.
    So it would be in frontend.js e.g.:

    
    var $form = $( this );
    
    if( $form.hasClass('swatches-support')) {
       return;
    }
    
    $form
       .addClass( 'swatches-support' )
       .on( 'click', '.swatch', function ( e ) {
       [...]
    
    Dash Commerce

    (@dashcommerce)

    Hi Philipp,

    No luck so far.

    I have added your code at line 11: https://ibb.co/v44X3KM

    and I am getting this error: https://ibb.co/dBNnWhh

    I have tried to put this snippet in other parts of the code and the error disappears, but the swatches plugin is still not working with product bundles.

    Dash Commerce

    (@dashcommerce)

    Hey Phillip, I have solved the issue.

    I’ve put this code in the Product Bundle plugin:

    //Put in the Woocommerce Product Bundle plugin.
    
    function hide_out_of_stock_option( $option ){
    	return 'yes';
    }
     
    add_action( 'woocommerce_before_template_part', function( $template_name ) {
     
    	
    
    	if( $template_name !== "single-product/add-to-cart/bundle.php" ) {
    		//var_dump($template_name);
    		return;
    	}
    	add_filter( 'pre_option_woocommerce_hide_out_of_stock_items', 'hide_out_of_stock_option' );
     
    } );
     
    add_action( 'woocommerce_after_template_part', function( $template_name ) {
     
    	if( $template_name !== "single-product/add-to-cart/bundle.php"  ) {
    		return;
    	}
     
    	remove_filter( 'pre_option_woocommerce_hide_out_of_stock_items', 'hide_out_of_stock_option' );
     
    } );
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.