i am new to both php and worldpress and i am doing a validation code for a Ecommerce site and i managed to do this
function so_validate_add_cart_item( $passed, $product_id, $quantity,
$variation_id = '', $variations= '' )
{
if ( 1 != 3 ){
$passed = false;
wc_add_notice( __( 'You can not do that', 'textdomain' ), 'error' );
}
return $passed;
}
add_filter( 'woocommerce_add_to_cart_validation',
'so_validate_add_cart_item', 10, 5 );
the thing is, this is just a generic thing(it doesnt even have a cart amount in it, its just a failure to test) but my system has a step by step "create your own pack" and each step has a different amount of items that you have to select, so i need to know how i do a check with different conditions in everystep, meaning how do i tell the site to do something in one page and something in another
If you want to check for all cart items details including quantity of each item you can access cart data from global $woocommerce
function so_validate_add_cart_item( $passed, $product_id, $quantity,
$variation_id = '', $variations= '' )
{
global $woocommerce;
$cart_items = $woocommerce->cart->get_cart();
//enter code here
if ( 1 != 3 ){
$passed = false;
wc_add_notice( __( 'You can not do that', 'textdomain' ), 'error' );
}
return $passed;
}
add_filter( 'woocommerce_add_to_cart_validation',
'so_validate_add_cart_item', 10, 5 );
hope this helps.