0

I run a WooCommerce store with three types of packaging; sold individually, sold in bulk of 6 and sold in bulk of 12. These packagings are tagged by a taxonomy called criteria with the terms 6-pack and 12-pack.

With the code below, which I have in functions.php, the quantity steps on the bulk products are increased by 6 or 12. So far everything works just as planned.

The problem: when going to the cart page the quantity steps doesn’t work. That means that suddenly the steps for any product is 1, which means that a customer can change 12 to 13 instead of 24, etc.

Any ideas on how to keep the quantity steps on the cart page as well?

add_filter( 'woocommerce_quantity_input_args', 'input_set_all_values', 1, 2 );

function input_set_all_values( $args, $product ) { 
    if (( has_term('6-pack', 'criteria' ) ) ) {
    $args['step'] = 6;
    $args['min_value'] = 6;
    return $args;
    }
if (( has_term('12-pack', 'criteria' ) ) ) {
    $args['step'] = 12;
    $args['min_value'] = 12;
    return $args;
    }
else {
    $args['step'] = 1;
    $args['min_value'] = 1;
    return $args;
    }
}
  • Why did you add is_singular( 'product' ) ? Remove it! – Sumit Apr 21 '16 at 7:18
  • I removed it but unfortunately it didn’t do the trick. – MadLandley Apr 21 '16 at 7:27
  • Please edit your question with updated code! – Sumit Apr 21 '16 at 7:33
  • Yep, sorry about that. – MadLandley Apr 21 '16 at 7:59
  • I realize that I have a follow up question to this (not sure if I should add this to my original question?). The solution to add $product->post worked on product page and in cart, but is it possible to add 6 or 12 when clicking on the add to cart button in the store listing? – MadLandley Apr 27 '16 at 8:28
0

Problem is on cart page has_term is false because it is checking if cart page have terms 12-pack or 6-pack. You also need to provide post object/ID to has_term() as a third parameter.

Updated code:-

function input_set_all_values( $args, $product ) { 
    if (( has_term('6-pack', 'criteria', $product->post ) ) ) {
        $args['step'] = 6;
        $args['min_value'] = 6;
        return $args;
    } else if (( has_term('12-pack', 'criteria', $product->post ) ) ) {
        $args['step'] = 12;
        $args['min_value'] = 12;
        return $args;
    } else {
        $args['step'] = 1;
        $args['min_value'] = 1;
        return $args;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.