Trying to block checkout page
-
Hey guys
Basiclaly I’m writing a function that whenever someone adds items to their cart that add up to over £250 the order doesn’t let them checkout. So far with this code their purchase is blocked but they are still allowed in the checkout page. I’d like to remove or hide the proceed to checkout button or display the message when proceed to checkout is pushed. Here is what I have so far. Any suggestions? Many thanks in advance.
/** * Set maximum order amount * */ add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' ); add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' ); function wc_minimum_order_amount() { // Set this variable to specify a maximum order value $maximum = 250; // get current user from wordpress $user = wp_get_current_user(); // if users role is any of these in the array $allowed_roles = array('editor', 'author', 'wholesale_customer'); if( array_intersect($allowed_roles, $user->roles ) ) { // Stuff here for allowed roles if ( WC()->cart->total > $maximum ) { if( is_cart() ) { remove_action( 'woocommerce_proceed_to_checkout','woocommerce_button_proceed_to_checkout', 20); wc_add_notice( sprintf( 'Your current order total is %s — this exceeds the %s limit. ' , wc_price( WC()->cart->total ), wc_price( $maximum ) ), 'error' ); return false; } else { remove_action( 'woocommerce_proceed_to_checkout','woocommerce_button_proceed_to_checkout', 20); wc_add_notice( sprintf( 'Your current order total is %s — this exceeds the order maximum of %s to place your order.' , wc_price( WC()->cart->total ), wc_price( $maximum ) ), 'error' ); return false; } } } }The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Trying to block checkout page’ is closed to new replies.