Does anyone know of a filter or hook that can be applied to insert a function before an item is inserted into a cart using WooCommerce? I have a similar issue as this post:
WordPress. Woocommerce. Action hook BEFORE adding to cart
But that OP’s comments don’t seem to work or are so vague I can’t get them to work and I can find no documentation regarding woocommerce_before_add_to_cart.
What I’m trying to do is just display an error, I’ll add logic once I can hook into the right action:
function checkProd(){
global $woocommerce;
$woocommerce->add_error( __('ERROR', 'woocommerce') );
return;
}
add_action( 'woocommerce_variable_add_to_cart', 'checkProd');
The best resource that I’ve found for woocommerce hooks is actually the repository itself, they have incredibly well commented code that is very readable.
https://github.com/woocommerce/woocommerce/blob/master/includes/wc-template-hooks.php
I’m sure a solution exists for the problem you’re trying to solve in one of these sections:
If you continue to have issues leveraging the above action hooks feel free to throw me a few more details and I can try to walk you through. Good luck!
I needed to do some actions before add to cart, so I did it this way
$_REQUEST used to process both GET and POST requests.