woocommerce 单品页面中具有固定数量的附加添加到购物车按钮

问题描述 投票:0回答:2

启用 woocommerce 后,我们可以在网上商店销售葡萄酒。

我想要一个额外的按钮,以便顾客可以购买一箱葡萄酒(12 瓶),而不必选择

qty= 12

我想将该按钮粘贴在每个单个产品页面上的

'add to cart'
按钮后面。

到目前为止我还找不到确切的方法。

php wordpress woocommerce product product-quantity
2个回答
6
投票

可以通过显示附加按钮的自定义挂钩功能轻松完成,只需在单个产品页面上单击 1 次即可添加 12 个产品(仅适用于简单产品):

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

代码位于活动子主题(活动主题)的 function.php 文件中。

已测试且有效。


0
投票

在 Google 中搜索“woocommerce 自定义添加到购物车按钮”显示了如何影响网址和文本,搜索“woocommerce 添加自定义按钮”显示了如何在各个页面中添加额外的 ui 按钮。

正如其他人在这里发布的那样,似乎还有许多插件使这变得更加简单,其中一些插件出现在我上面列出的搜索中,例如“最小/最大数量”

https://wordpress.org/plugins/woo-min-max-quantity-limit/

https://wordpress.org/plugins/minmax-quantity-for-woocommerce/

© www.soinside.com 2019 - 2024. All rights reserved.