Enable ajax add to cart for variable products with a specific category

This topic has 6 replies, 3 voices, and was last updated 6 months, 4 weeks ago ago by Andrew Mitchell

  • Avatar: Lucas
    Lucas
    Participant
    April 25, 2024 at 10:58

    Hello support,

    I disabled “Ajax add to cart” for variable products in the theme options in order to use a third party plugin and it is working very well.

    But I still would like to keep the ajax add to cart option only for variable products which have a specific category which in my case is “Collection voyage” (category with ID 64).
    Can you help me on doing this please?

    Thanks in advance,
    Lucas

    5 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    April 26, 2024 at 05:19

    Hi @Lucas,

    To remove the AJAX ADD TO CART scripts, please add the following code under functions.php file locates in your child theme:

    
    add_action( 'wp_enqueue_scripts', 'n2t_theme_enqueue_styles', 1001 );
    function n2t_theme_enqueue_styles() {
    	if( has_term( array( 'vases' ), 'product_cat' ) ) {
            wp_dequeue_script('etheme_spv_ajax_add_to_cart');
        }
    }
    

    Replace the vases slug, with your Collection voyage category slug, we guess it might be: collection-voyage.

    Hope it helps!

    Avatar: Lucas
    Lucas
    Participant
    April 26, 2024 at 07:46

    Hello Luca,

    Sorry it is not working, the page is still reloading when I add to cart the product in category collection-voyage from the product single page. I would like it to behave like this : (see screenshot attached) where I can see the popup open without the page reloading.

    Thanks,
    Lucas

    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff
    April 26, 2024 at 10:31

    Hi @Lucas,

    I disabled “Ajax add to cart” for variable products in the theme options in order to use a third party plugin and it is working very well.

    In this case, please enable this option again.

    After that, update the code to this:

    
    add_action( 'wp_enqueue_scripts', 'n2t_theme_enqueue_styles', 1001 );
    function n2t_theme_enqueue_styles() {
        if( !has_term( array( 'collection-voyage' ), 'product_cat' ) ) {
            wp_dequeue_script('etheme_spv_ajax_add_to_cart');
        }
    }
    

    Please note that the codes above will disable the AJAX add to cart on single product page only.

    Hope it helps!

    Avatar: Lucas
    Lucas
    Participant
    April 26, 2024 at 10:57

    Hi @Luca Rossi,

    Excellent, this works very well !

    Thanks again,
    Lucas

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    April 26, 2024 at 10:57

    Dear Lucas,

    We hope you’re reveling in the experience our theme brings! Your enthusiasm is what fuels our passion. Would you be so kind as to channel that energy into a 5-star rating on ThemeForest? Your feedback is the spark that lights our way!

    Click here to spread the love: https://themeforest.net/downloads

    Thank you for being an integral part of our journey!

    Best Regards,
    The 8Theme Team

  • Viewing 6 results - 1 through 6 (of 6 total)

The issue related to '‘Enable ajax add to cart for variable products with a specific category’' has been successfully resolved, and the topic is now closed for further responses

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.