Skip to content

Instantly share code, notes, and snippets.

@woogists
Last active March 11, 2022 06:41
Show Gist options
  • 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 );
@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