php - WooCommerce - 如果金额大于 x,则将每个运费设置为 0(我有 90% 的工作片段但无法修改)
问题描述
我找到了一个几乎完美的片段,我觉得很傻,但无法修改它以满足我的需要。
它是什么:
if price is above 10--> shipping cost 4.5
if price is under 10--> shipping cost 2.5
我需要的:
if price is above 10000--> shipping cost 0 (and display 0 next to each shipping method if it's not too hard)
if price is under 10000 --> keep original pricing set in WooCommerce settings
如果你能帮助我,非常感谢!有一个非常愉快的一天!
https://reigelgallarde.me/programming/woocommerce-shipping-fee-changes-condition-met/
add_filter( 'woocommerce_package_rates', 'woocommerce_package_rates', 10, 2 );
function woocommerce_package_rates( $rates, $package ) {
$new_cost = ( WC()->cart->subtotal < 10 ) ? 4.5 : 2.5;
foreach($rates as $key => $rate ) {
$rates[$key]->cost = $new_cost;
}
return $rates;
}
解决方案
推荐阅读
- node.js - Puppeteer 错误找不到选择器的节点(按钮单击)
- php - 将桌子与 foreach 并排放置
- mysql - 如何查询工作中有字母(例如K)且薪水大于某个数字的姓名
- python - 我怎样才能总结一天的时间戳?
- javascript - 如何将源转换为我的资产 img ?角
- angular - 删除查询参数后如何防止滚动到顶部?
- wiki - 如何在 cytoscape 中打开 wikipathway(作为通路)?
- javascript - 如何在render()reactjs中定义useState变量
- objective-c - 如何画一条简单的直线?
- code-signing - 带有标准代码签名证书的智能屏幕过滤器