Home Forums WoodMart support forum permanent changes / overwrite in a woodmart .js file, possible?

permanent changes / overwrite in a woodmart .js file, possible?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #305921

    iwanwilaga
    Participant

    Hello,

    I needed to implement FB pixel tracking to work with Woodmart & ajax add-to-cart button. For this i needed to modify ../wp-content/themes/woodmart/js/scripts/wc/addToCartAllTypes.js file.

    My question: is it possible to somehow keep this change safe from being overwritten by Woodmart theme updates? I do hope so.
    Thank you,
    Wiktor

    #306041

    Artem Temos
    Keymaster

    Hello,

    This file can’t be overridden in the child theme. But as a workaround, you can disable it completely via Theme Settings -> Performance JS and copy its code to the new JS file that will be loaded in the child theme. Here is an article that should help you to load a new JS file on your website https://kinsta.com/blog/wp-enqueue-scripts/

    Kind Regards

    #306653

    iwanwilaga
    Participant

    Hi, Artem,

    Thank you for your solution. I consider doing it. Before, let me ask our opinion about this solution:

    function override_woodmart_theme_scripts() {
        global $wp_scripts; 
        $wp_scripts->registered['add-to-cart-all-types']->src = get_stylesheet_directory_uri() . '/js/scripts/wc/addToCartAllTypes.js';
    }
    add_action('wp_enqueue_scripts', 'override_woodmart_theme_scripts');

    (https://stackoverflow.com/questions/11852570/override-woocommerce-frontend-javascript)

    This seems also a very straightforward ‘swap’ solution. Do you know any drawbacks about this one?

    Thank you, have a great day!
    Wiktor

    #306680

    Artem Temos
    Keymaster

    Hello,

    We haven’t tested this solution but yes, it looks correct and should work perfectly. Let us know how it works after your tests.

    Kind Regards

    #306698

    iwanwilaga
    Participant

    It seems workin’, but with a slight modification:

    I found that the script handler must be wd-add-to-cart-all-types instead of add-to-cart-all-types. Somewhere you add the wd- prefix at script registration apparently.

    so this works for me by now:

    function override_woodmart_theme_scripts() {
        global $wp_scripts; 
        $wp_scripts->registered['wd-add-to-cart-all-types']->src = get_stylesheet_directory_uri() . '/js/scripts/wc/addToCartAllTypes.js';
    }
    add_action('wp_enqueue_scripts', 'override_woodmart_theme_scripts', 21); // under '21' priority it threw fatal error to me.

    Best wishes,
    Wiktor

    #306789

    Artem Temos
    Keymaster

    Yes, that’s correct. We are glad that you sorted it out. Let us know if you need any further assistance.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘permanent changes / overwrite in a woodmart .js file, possible?’ is closed to new replies.