Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

before add to cart hook woocommerce

function so_validate_add_cart_item( $passed, $product_id, $quantity, $variation_id = '', $variations= '' ) {

    // do your validation, if not met switch $passed to false
    if ( 1 != 2 ){
        $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 );
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #cart #hook #woocommerce
ADD COMMENT
Topic
Name
7+9 =