WooCommerce-添加免费用户计划的运费 [英] WooCommerce - Adding shipping fee for free user plan

查看:155
本文介绍了WooCommerce-添加免费用户计划的运费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WooCommerce,并且使用了付费会员专业版免费插件.

I am using WooCommerce and with Paid Memberships Pro free plugin.

在网站上,我们有2个计划(免费计划和付费计划):

On the web site we have 2 plans (a free plan and a paid plan):

  • 免费用户每月可以购买1件商品,
  • 付费用户每月可以购买4件商品.

现在,我不知道如何简单地使用以下代码在结帐页面上计算运费:

Now I don't know how to simply calculate shipping on checkout page with code like:

if (pmpro_hasMembershipLevel('2')) { // Paid plan

    //free shipping (0$)

} else {

    //add shipping 4$ to checkout

}

没有运输类别,没有区域影响运输价格.

No shipping class, No region zone is affect shipping price.

我试图设置运送"选项,但我无法摆脱它.

I have tried to set Shipping options, but I can’t get rid of it.

我该如何实现?

谢谢.

推荐答案

自WooCommerce 2.6+起,运输已进行了改型,并且如您所愿,在没有插件的情况下对其进行自定义非常复杂……相反,您要做的是添加一个费用取决于您的用户级别和其他条件(如果需要).

Since WooCommerce 2.6+, shipping has been remodeled, and is quite complicated to customize it as you would like, without a plugin… Instead you do, is adding a fee based on your user levels and other conditions if needed.

这是我的代码:

function add_shipping_fee( ) {

    // Set here your shipping fee amount
    $fee = 4;

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( pmpro_hasMembershipLevel('2') == false)
        WC()->cart->add_fee( __('Shipping Fee:', 'your_theme_slug'), $fee, false );
}
add_action( 'woocommerce_cart_calculate_fees','add_shipping_fee' );

这很自然地出现在活动子主题(或主题)的function.php文件或任何插件文件中.

此代码已经过测试并且可以正常工作.

参考:

  • WooCommerce - Make a set of coupons adding a fixed fee to an order
  • WooCommerce class - WC_Cart - add_fee() method

这篇关于WooCommerce-添加免费用户计划的运费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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