Okay
  Public Ticket #4413766
Add to cart needs to clear
Open

Comments

  •  3
    John Adcox started the conversation

    The add to cart button should only let them checkout with what's currently in the quote, how can we set this to clear the cart, and then add the items?

    Attached files:  Screenshot 2025-08-26 at 8.12.55 AM.png

  •  2,500
    WebWizards replied

    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

  •  3
    John Adcox replied

    That did not work for us, but some heavy modifications of the code worked, you can close this ticket, thank you.