Public Ticket #4413766

Add to cart needs to clear

Closed
Comments
2,762
KingsPlugins replied 1 year ago on August 26, 2025 at 7:16pm

Hi John,

I understand you want to first clear the cart when clicking that 'add offer to cart' button.

You can add the following code to your theme's functions.php file or use a code snippets plugin:

function empty_cart_before_offer($offer_id) {
    // Check if WooCommerce is active and cart exists
    if (function_exists('WC') && WC()->cart) {
        // Empty the cart
        WC()->cart->empty_cart();
           }
}

add_action('b2bking_add_offer_start_ajax', 'empty_cart_before_offer', 10, 1);

Let me know if you run into any issues!

Kind regards,
Stefan

Sign In