• Resolved tomassande

    (@tomassande)


    Hi there,
    I’m struggling with this since a couple of days ago. My client wants to prevent users to add tickets to the cart (and ultimately buying them) if they don’ meet certain requirements. They have 3 different options: 1 sell all together, 2 sell in pairs and 3 buy any amount but don’t leave only one left

    That said, I have the logic in place with the error messages ready, but it seems that the validation is done but the order gets cancelled and Woocommerce redirects to my empty-cart.php site. Instead of staying in the same page and showing the error. I’m trying to prevent this redirection and stay on the same website, showing the error message, but somehow this is not working. If I use manual redirections, they are done, but the error message is somehow lost.

    Here’s my code:

    add_action( ‘woocommerce_add_to_cart_validation’, ‘ts_sell_validation’, 1, 3);

    function ts_sell_validation($passed,$product_id,$quantity){
    global $woocommerce;
    $meta=[];
    $passed=true;
    $meta=get_post_meta($product_id);
    if($meta[‘juntas’][0] == 1) :
    if($quantity < $meta[‘_stock’][0] ):
    wc_add_notice( sprintf( __( “The selected tickets were published to be sold all together. You should select “.$meta[‘_stock’][0].” (all of them)”, “your-theme-language” ) ) ,’error’ );
    $passed=false;
    endif;
    elseif($meta[‘juntas’][0] == 2 ):
    if( ($meta[‘_stock’][0] – $quantity) == 1 ):
    wc_add_notice( sprintf( __( “The tickets selected were.. “, “your-theme-language” ) ) ,’error’ );
    $passed=false;
    endif;
    elseif($meta[‘juntas’][0] == 3) :
    if( ( $quantity % 2) != 0 ) :
    wc_add_notice( sprintf( __( “The tickets selected were.. “, “your-theme-language” ) ) ,’error’ );
    $passed=false;
    endif;
    endif;
    return $passed;
    }

    Thanks,

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Erica

    (@eeide)

    Hi @tomassande,

    It looks like you have an active Event Tickets Plus license! Please open a ticket at theeventscalendar.com/support/ so we can assist you through our premium support, as we are unable to support customers of premium plugins in these forums.

    Thank you,
    Erica

    Plugin Support Abz

    (@abzlevelup)

    Hi @tomassande,

    We haven’t heard from you in a while, so I’m going to mark this as resolved. Feel free to start a new thread if you have any more questions.

    Best,
    Abz

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Prevent Cart redirection in woocommerce_add_to_cart_validation’ is closed to new replies.