简体   繁体   中英

woocommerce variations and Quantity steps

woocommerce sample product have A,B,C variants i want do that, when choosed "A" variant, Quantity steps goes to 12,24,36... for "B", 6,12,18 ...for "C" 10, 20 ,30 ... found an code for Quantity steps, but i dont know how to modify it for that thanks for help

// Simple products
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );
function jk_woocommerce_quantity_input_args( $args, $product ) {
$args['input_value'] = 2; // Starting value
$args['max_value'] = 80; // Maximum value
$args['min_value'] = 2; // Minimum value
$args['step'] = 2; // Quantity steps
return $args;
}

// Variations
add_filter( 'woocommerce_available_variation', 'jk_woocommerce_available_variation' );
function jk_woocommerce_available_variation( $args ) {
$args['max_qty'] = 80; // Maximum value (variations)
$args['min_qty'] = 2; // Minimum value (variations)
return $args;
}

/////////////////////////////////////////////// I can pay for that 30$ who want supply my request

before these code, i added custom field "_pro_pack_box" and "_pro_pcs_pack". you can see this article .

// Simple products
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );

function jk_woocommerce_quantity_input_args( $args, $product ) {
    $pack_box = get_post_meta($product->post->ID, "_pro_pack_box", true);
    $pcs_pack = get_post_meta($product->post->ID, "_pro_pcs_pack", true);
    //if ( is_singular( 'product' ) ) {
    //  $args['input_value']    = 2;    // Starting value (we only want to affect product pages, not cart)
    //}
    //$args['max_value']    = 80;   // Maximum value
    $args['min_value']  = $pcs_pack;    // Minimum value
    $args['step']       = $pcs_pack;    // Quantity steps
    return $args;
}

// Variations
add_filter( 'woocommerce_available_variation', 'jk_woocommerce_available_variation' );

function jk_woocommerce_available_variation( $args ) {
    //$args['max_qty'] = 80;        // Maximum value (variations)
    $args['min_qty'] = $pcs_pack;       // Minimum value (variations)
    return $args;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM