• Resolved crimsonhack

    (@crimsonhack)


    I am creating an online store which should only allow a single product in the cart, that is, there is no possibility to add a second product. I found the following code that makes this possible:

    add_filter( 'woocommerce_add_cart_item_data', 'mk_only_one_item_in_cart', 10, 1 );
    
    function mk_only_one_item_in_cart( $cartItemData ) {
    	wc_empty_cart();
    
    	return $cartItemData;
    }

    So far so good, but one of the products in the store requires the addition of a second product, in other words, a forced sale. Would it be possible to modify this code so that this particular product would allow two products in the cart? I don’t know if I’m making myself clear.

    Thank you very much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Daniyal Ahmed (a11n)

    (@daniyalahmedk)

    Hi there,

    Thanks for reaching out.

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Best,

    Thread Starter crimsonhack

    (@crimsonhack)

    Thank you very much Daniyal, hopefully someone can help me.

    Thread Starter crimsonhack

    (@crimsonhack)

    I will try to explain better. The intention of the store is that the customer can only add a single item to the cart, I got that with the code I mentioned above.

    What I intend to do is that in certain products the cart can accept two items instead of one. Let me put you in context.

    The store is for a high school, they want to offer online tuition payment. Each tuition is an item (aka product), they select it and add it to the cart to be paid. The thing is that one of the tuition that they offer requires a forced sale, that means that a second item will be added to the cart, but that code does not allow me to do so since it requires only one item in the cart.

    What I am asking is if this code can be modified to add an exception to the tuition that requires a forced sale. In other words, tell the code to do its function but to make an exception for that specific item (I guess by product ID).

    I hope I have expressed myself better.

    Plugin Support Chris Moreira – a11n

    (@chrism245)

    Hello!

    As mentioned before, the #developers channel of the WooCommerce Community Slack: https://woocommerce.com/community-slack/. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well. — It will be good you contact a developer to help with this.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Limit cart to a single product’ is closed to new replies.