Forum Replies Created

Viewing 1 replies (of 1 total)
  • Hi, busy working on a Wine shop where I also needed to sell in multiples of 6. I got it to work with this code (added to my function.php)

    add_action('the_post','order_steps_func',10);
    function order_steps_func(){
    global $woocommerce;
    if (is_checkout()){
    $steps = 6;
    if( $woocommerce->cart->cart_contents_count % 6 != 0){
     $woocommerce->add_error( sprintf(__('Sorry, you must order in multiples of ' . $steps . ' bottles. Please adjust your cart or <a href="%s/shop">return to the shop to add more →</a>', 'woocommerce'), home_url()) );
        wp_redirect( get_permalink( woocommerce_get_page_id( 'cart' ) ) );
       			exit;
    }}}

    So this fires when loading the checkout page and basically just checks if the cart total (cart_contents_count) is divisible by 6. If not it shows a error message on the cart page. Just change the values to whatever you need.

    I am not a PHP guru but got this to work, hope it helps.

Viewing 1 replies (of 1 total)