Last active
March 11, 2022 06:41
-
-
Save woogists/ab484a0998956d3b1cb934590eb960e7 to your computer and use it in GitHub Desktop.
[WooCommerce Force Sells] Only force sell one product
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 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 ); |
I updated this snippet to fix a critical error triggered due to the number of parameters on the wc_force_sell_update_quantity
filter
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
How to apply this rule to a specific products IDs or categories?
Thanks.