问题描述
在 WooCommerce 3 中,我有以下运输选项(设置):
In WooCommerce 3, I have these shipping options (settings):
- 免运费:
free_shipping:1- 最低订单金额设为$50. - 正常运输
flat_rate:3- 金额$5. - 快递
flat_rate:5- 金额$10.
- Free Shipping:
free_shipping:1- Minimum order amount is set at$50. - Normal Shipping
flat_rate:3- Amount$5. - Express Shipping
flat_rate:5- Amount$10.
我希望 快递 选项始终可用(如图所示).
I would like Express Shipping option to be always available (shown).
但是当免费送货可用时(意味着客户在购物车中的金额超过 50 美元),我只想隐藏正常送货.
But when Free shipping is available (meaning that the customer has more than $50 in the cart) I would like to hide Normal Shipping only.
因此,当免费送货不可用(和隐藏)时,可用的运费将为正常送货 和快递.
So when Free shipping is NOT available (and hidden), the available shipping rates will be Normal Shipping and Express Shipping.
这可能吗?我怎样才能在 WooCommerce 3 上获得这个?
Is that possible? How can I get this on WooCommerce 3?
推荐答案
基于 WooCommerce 官方代码段,做了一些小改动,当免费送货可用时,您将只能隐藏您的第一个统一费率:
Based on the official WooCommerce snippet code, making some light changes, you will be able to hide only your first flat rate when free shippings is available:
add_filter( 'woocommerce_package_rates', 'conditionally_hide_shipping_methods', 100, 2 );
function conditionally_hide_shipping_methods( $rates, $package ) {
// HERE yours 2nd flat rate "Express Shipping" (that you never hide) in the array:
$flat_rates_express = array( 'flat_rate:5', 'flat_rate:12', 'flat_rate:14' );
$free = $flat2 = array();
foreach ( $rates as $rate_key => $rate ) {
// Updated Here To
if ( in_array( $rate->id, $flat_rates_express ) )
$flat2[ $rate_key ] = $rate;
if ( 'free_shipping' === $rate->method_id )
$free[ $rate_key ] = $rate;
}
return ! empty( $free ) ? array_merge( $free, $flat2 ) : $rates;
}
代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.
在 WooCommerce 3 上测试并有效.
Tested on WooCommerce 3 and works.
刷新运输缓存:
1) 首先清空您的购物车.
2) 此代码已保存在您的 function.php 文件中.
3) 进入运输区域设置并禁用一个统一费率"(例如) 和保存".然后重新启用统一费率"和保存".大功告成,可以进行测试了.
Refresh the shipping caches:
1) First empty your cart.
2) This code is already saved on your function.php file.
3) Go in a shipping zone settings and disable one "flat rate" (for example) and "save". Then re-enable that "flat rate" and "save". You are done and you can test it.
这篇关于在 WooCommerce 3 中提供免费送货时隐藏特定的统一费率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)