Last active
January 7, 2020 18:00
-
-
Save BFTrick/7137572 to your computer and use it in GitHub Desktop.
If you want to use WooCommerce Force Sells to add only one of the force sold products to the cart.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// only add one force sell product to the cart no matter how many of the original product are added | |
function my_wc_force_sell_add_to_cart_product( $product ){ | |
$product['quantity'] = 1; | |
return $product; | |
} | |
add_filter( 'wc_force_sell_add_to_cart_product', 'my_wc_force_sell_add_to_cart_product' ); | |
// when a synced force sell product is updated always set it to 1 | |
function my_wc_force_sell_update_quantity( $quantity, $product ){ | |
return 1; | |
} | |
add_filter( 'wc_force_sell_update_quantity', 'my_wc_force_sell_update_quantity' ); |
I have single product( type of service) and 8-10 adson(type of products). I want to force single product (service) when user add adson to cart.
The issue is I want only single service product into cart but it added multiple times when user add different adson to cart.
The above code is not working, Can you please let me know how I can fix it ?
Thanks in advance.
Expert
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any ideas on how to allow only one of the force sold items into the entire cart....not just per product? So if I have the same item as a force sell for several products, and I only want one of the force sell items to be added to the cart in its entirety, not one for each different product it's attached to...