woocommerce变化和数量步骤

时间:2014-09-08 12:40:40

标签: javascript php wordpress woocommerce

woocommerce样本产品有A,B,C变体 我想这样做,当选择“A”变种时,数量步长为12,24,36 ...为“B”,6,12,18 ...为“C”10,20,30 ... 找到了数量步骤的代码,但我不知道如何修改它 谢谢你的帮助

// 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;
}

/////////////////////////////////////////////// 我可以支付那些想要提供我的请求的30美元

1 个答案:

答案 0 :(得分:1)

在这些代码之前,我添加了自定义字段" _pro_pack_box"和" _pro_pcs_pack"。 你可以看到这个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;
}