• Resolved amila

    (@flatworld21)


    Hi, I need to empty cart before add_to_cart,
    If I add “WC_Cart::empty_cart()” to function add_to_cart in includes/class-wc-cart.php it works.

    But if I add the following code in functions.php

    add_filter( ‘woocommerce_add_to_cart_validation’, ‘woo_custom_add_to_cart_before’ );
    function woo_custom_add_to_cart_before( $cart_item_data ) {
    global $woocommerce;
    WC_Cart::empty_cart();
    // Do nothing with the data and return
    return true;
    }

    I get an error in page:
    jquery.js?ver=1.12.4:4 POST http://www.xxxxxxxx.com/?wc-ajax=add_to_cart 500 (Internal Server Error)

    I do not want to change core source. How to solve it?

    • This topic was modified 7 years, 11 months ago by amila.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘empty cart before add’ is closed to new replies.