Skip to content

Instantly share code, notes, and snippets.

@woogists
Last active March 11, 2022 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woogists/ab484a0998956d3b1cb934590eb960e7 to your computer and use it in GitHub Desktop.
Save woogists/ab484a0998956d3b1cb934590eb960e7 to your computer and use it in GitHub Desktop.
[WooCommerce Force Sells] Only force sell one product
// only add one force sell item per product 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', 10, 2 );
@obryhidyr
Copy link

How to apply this rule to a specific products IDs or categories?
Thanks.

@martynmjones
Copy link

martynmjones commented Nov 25, 2021

I updated this snippet to fix a critical error triggered due to the number of parameters on the wc_force_sell_update_quantity filter

@imjaypee
Copy link

How to apply this rule to specific product IDs on function? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment