• Resolved safnasash

    (@safnasash)


    Hello,

    i am using variations, and i used a script to add button if the variation found , the script is

    function bbloomer_echo_variation_info() {
    global $product;
    if ( ! $product->is_type( ‘variable’ ) ) return;
    echo ‘

    Download Data Sheet‘;
    wc_enqueue_js( “
    jQuery.noConflict();
    jQuery(document).on(‘found_variation’, ‘form.cart’, function( event, variation ) {

         var fid= variation.variation_description;
        var fpath = jQuery(fid).text();      
         jQuery('.svar').attr('href', fpath);
         if(fpath){
         jQuery('.var_info').css('display', 'block');
         }
         else{
            jQuery('.var_info').css('display', 'none');
         }
        });

    ” );
    }

    it works fine for 2 products i have tested, when i add new product with 5 variations , it not working and shows console with error

    Uncaught TypeError: i.$form.block is not a function
    at t.onFindVariation (add-to-cart-variation.min.js?ver=7.9.0:1:4310)
    at HTMLFormElement.dispatch (jquery.min.js?ver=1.0.0:2:43090)
    at v.handle (jquery.min.js?ver=1.0.0:2:41074)
    at Object.trigger (jquery.min.js?ver=1.0.0:2:71513)
    at HTMLFormElement. (jquery.min.js?ver=1.0.0:2:72108)
    at Function.each (jquery.min.js?ver=1.0.0:2:2976)
    at S.fn.init.each (jquery.min.js?ver=1.0.0:2:1454)
    at S.fn.init.trigger (jquery.min.js?ver=1.0.0:2:72084)
    at t.onChange (add-to-cart-variation.min.js?ver=7.9.0:1:7330)
    at HTMLFormElement.dispatch (jquery.min.js?ver=1.0.0:2:43090)

Viewing 3 replies - 1 through 3 (of 3 total)
  • con

    (@conschneider)

    Engineer

    Hi there,

    Based on the error message it seems something maybe overwriting the block function. Have you tried a conflict check yet?

    https://ww.wp.xz.cn/plugins/check-conflicts/ allows you to do one for your IP only.

    Do you get the same with only WooCommerce active?

    Kind regards,

    Thread Starter safnasash

    (@safnasash)

    hello,

    thank you for your reply

    i checked the conflicts and i still get the same error with only woocommerce active. also please note that, for my 2 products, it works fine and not showing any console error.eg: http://aewis.com/product/discreto-recessed-luminaires-round/

    but for the newly adding products with 50 variations , its not working. when it for 14 variations it works and not showing any console error, so i cant identify what the error is happening.

    i removed my script and i just checked the console after choose a variation, it still shows the console error. so its completely related to the variation found function.

    con

    (@conschneider)

    Engineer

    Hi again,

    We can try and make sure that your custom script is enqueued after jquery, jquery-blockui, and wc-add-to-cart-variation. For that we should move it to a separate file:

    Here is an example of how you can enqueue your script:

    
    function bbloomer_enqueue_variation_script() {
        if ( is_product() ) {
            wp_enqueue_script( 'bbloomer-variation-script', plugin_dir_url( __FILE__ ) . 'js/variation-script.js', array( 'jquery', 'jquery-blockui', 'wc-add-to-cart-variation' ), '1.0', true );
        }
    }
    add_action( 'wp_enqueue_scripts', 'bbloomer_enqueue_variation_script' );
    

    And then you can move your JavaScript code to a new file variation-script.js:

    
    jQuery(document).on('found_variation', 'form.cart', function( event, variation ) {
        var fid = variation.variation_description;
        var fpath = jQuery(fid).text();      
        jQuery('.svar').attr('href', fpath);
        if(fpath){
            jQuery('.var_info').css('display', 'block');
        }
        else{
           jQuery('.var_info').css('display', 'none');
        }
    });
    

    Remember to replace plugin_dir_url( __FILE__ ) . 'js/variation-script.js' with the actual path to your JavaScript file.
    Also this code is very untested, take it with a grain of salt.

    Kind regards,

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘ncaught TypeError: i.$form.block is not a function’ is closed to new replies.