Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Last active January 7, 2020 18:00
Show Gist options
  • Save BFTrick/7137572 to your computer and use it in GitHub Desktop.
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.
// 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' );
@expertdeveloperit
Copy link

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