-
-
Save BFTrick/7137572 to your computer and use it in GitHub Desktop.
// 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' ); |
ok although I have no clue how to code PHP, I figured out that the 2nd argument in the 2nd function is not necessary, and only $quantity needs to be called. I hope this fixed it, bc looks like it did on my site.
Hi,
I detected a problem. When I add this code to the functions.php I see the following thing:
If I delete the main product in the cart the "forced" product still remain and there is no chance to delete it because there is no delete button for the forced prodoct. Only for the main prododuct there is a delete button.
Do you have an idea how to fix it?
Many thanks!
Regards,
Peter
// when a synced force sell product is updated set it to 1
// if products is removed set $quantity to 0
function my_wc_force_sell_update_quantity( $quantity){
return ($quantity==0) ? 0:1;
}
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...
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
can someone helped me? I'm a total newbie, and I keep copying this snippet into my functions.php file, but the first part works only. The 2nd part, when I updated my cart with the product quantity, i get this error, below. Line 97 equates to line "9" of the code above.
Warning: Missing argument 2 for my_wc_force_sell_update_quantity() in /homepages/18/d299944994/htdocs/clickandbuilds/WordPress/EnviroPros/wp-content/themes/brandon/functions.php on line 97
Warning: Cannot modify header information - headers already sent by (output started at /homepages/18/d299944994/htdocs/clickandbuilds/WordPress/EnviroPros/wp-content/themes/brandon/functions.php:97) in /homepages/18/d299944994/htdocs/clickandbuilds/WordPress/EnviroPros/wp-includes/pluggable.php on line 896