仅在产品页面而不是woocommerce购物车中插入下拉列表数量

时间:2019-06-02 11:42:41

标签: php wordpress woocommerce storefront

我想在产品描述页面上插入下拉数量选择器,并保持购物车的本机数量输入不变。我正在尝试使用以下代码,该代码在产品页面上效果很好,但购物车的数量也发生了变化。

请问我如何才能使此代码仅在产品页面上起作用而使购物车的输入数量保持不变?

function woocommerce_quantity_input() {
    global $product;
    $defaults = array(
        'input_name'    => 'quantity',
        'input_value'   => '1',
        'max_value'     => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
        'min_value'     => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
        'step'      => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
        'style'     => apply_filters( 'woocommerce_quantity_style', 'float:left; margin-right:10px;', $product )
    );
    if ( ! empty( $defaults['min_value'] ) )
        $min = $defaults['min_value'];
    else $min = 1;
    if ( ! empty( $defaults['max_value'] ) )
        $max = $defaults['max_value'];
    else $max = 20;
    if ( ! empty( $defaults['step'] ) )
        $step = $defaults['step'];
    else $step = 1;
    $options = '';
    for ( $count = $min; $count <= $max; $count = $count+$step ) {
        $options .= '<option value="' . $count . '">' . $count . '</option>';
    }
    echo '<div class="quantity_select" style="' . $defaults['style'] . '"><select name="' . esc_attr( $defaults['input_name'] ) . '" title="' . _x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) . '" class="qty">' . $options . '</select></div>';
}

0 个答案:

没有答案