根据自定义字段第二次添加到具有固定数量的购物车按钮

时间:2019-07-09 10:08:16

标签: woocommerce

我正在建立一家葡萄酒商店,我想在产品页面上添加2个购物车按钮。标准的一个按钮和第二个按钮可在购物车中添加一盒酒。

问题在于某些葡萄酒的包装盒中有6种,其他的则有12种。

我尝试了下面的代码,这些代码是我在stackoverflow上找到的,它确实可以工作在固定数量上。

我创建了一个自定义字段,其中包含用于包装盒子中瓶子数量的代码段:

  // Stuks per doos
woocommerce_wp_text_input( 
    array( 
        'id'          => '_stuks_doos', 
        'label'       => __( 'Stuks per doos', 'woocommerce' ), 
        'placeholder' => '',
        'desc_tip'    => 'true',
        'description' => __( 'Voer de VE per doos in.', 'woocommerce' ) ,
        'type'              => 'number'
    )
);

在以下代码中将我的数量= 12更改为我创建的自定义字段(_stuks_doos)时,我需要一些帮助

add_action( 'woocommerce_after_add_to_cart_button', 'additional_simple_add_to_cart', 20 );
function additional_simple_add_to_cart() {
    global $product;
    // Only for simple product type
    if( ! $product->is_type('simple') ) return;

    $href = '?add-to-cart=' . esc_attr( $product->get_id() ) . '&quantity=12';
    $class = 'ingle_add_to_cart_button-12 button alt';
    $style = 'display: inline-block; margin-top: 12px;';
    $button_text = __( "Add a case of 12", "woocommerce" );

    // Output
    echo '<br><a rel="no-follow" href="'.$href.'" class="'.$class.'" style="'.$style.'">'.$button_text.'</a>';
}

我还想知道是否有一种方法可以使此代码在ajax中运行

0 个答案:

没有答案
相关问题