在woocommerce单个产品页面中添加固定数量的添加到购物车按钮 [英] additional add to cart button with fixed quantity in woocommerce single product pages

查看:52
本文介绍了在woocommerce单个产品页面中添加固定数量的添加到购物车按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启用 woocommerce 后,我们会在我们的电子商店上销售葡萄酒.

With woocommerce enabled, we sell wine on our e-shop.

我想要一个附加按钮,以便客户可以购买一箱葡萄酒(12 瓶),而不必选择 qty=12.

I would like an additional button so that customer can buy a case of wine (12 bottles) rather than having to select qty= 12.

我想在每个单个产品页面上的 '添加到购物车' 按钮之后粘贴按钮.

I would like to stick the button after the 'add to cart' button on each single product page.

直到现在我还找不到确切的方法.

Until now I can't find exactly the way to do it.

推荐答案

它可以通过自定义挂钩函数轻松完成,该函数显示一个附加按钮,只需单击单个产品页面即可添加 12 个产品,仅适用于简单产品:

It can be done easily with a custom hooked function displaying an additional button that will add 12 products on 1 click on single product pages for simple products only:

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 文件中.

Code goes in function.php file of your active child theme (active theme).

经过测试并有效.

这篇关于在woocommerce单个产品页面中添加固定数量的添加到购物车按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆