Vid*_*dhi 7 php wordpress shipping woocommerce
我怎样才能获得woocommerce_free_shipping_min_amount在woocommerce中获得免费送货所需的最低订单金额(在管理面板中设置woocommerce - >设置 - >送货 - >免费送货 - >最低订单金额)?
我想在前端页面显示此价格
该值存储在option键下woocommerce_free_shipping_settings.它是一个由数组加载的数组WC_Settings_API->init_settings().
如果您想直接访问它,您可以使用get_option():
$free_shipping_settings = get_option( 'woocommerce_free_shipping_settings' );
$min_amount = $free_shipping_settings['min_amount'];
Run Code Online (Sandbox Code Playgroud)
从 WooCommerce 2.6 版开始,接受的答案不再有效。它仍然提供输出,但该输出是错误的,因为它没有使用新引入的运输区域。
为了获得特定区域免费送货的最低消费金额,请尝试使用我组合的此功能:
/**
* Accepts a zone name and returns its threshold for free shipping.
*
* @param $zone_name The name of the zone to get the threshold of. Case-sensitive.
* @return int The threshold corresponding to the zone, if there is any. If there is no such zone, or no free shipping method, null will be returned.
*/
function get_free_shipping_minimum($zone_name = 'England') {
if ( ! isset( $zone_name ) ) return null;
$result = null;
$zone = null;
$zones = WC_Shipping_Zones::get_zones();
foreach ( $zones as $z ) {
if ( $z['zone_name'] == $zone_name ) {
$zone = $z;
}
}
if ( $zone ) {
$shipping_methods_nl = $zone['shipping_methods'];
$free_shipping_method = null;
foreach ( $shipping_methods_nl as $method ) {
if ( $method->id == 'free_shipping' ) {
$free_shipping_method = $method;
break;
}
}
if ( $free_shipping_method ) {
$result = $free_shipping_method->min_amount;
}
}
return $result;
}
Run Code Online (Sandbox Code Playgroud)
将上面的函数放在functions.php 中,并在模板中使用它,如下所示:
$free_shipping_min = '45';
$free_shipping_en = get_free_shipping_minimum( 'England' );
if ( $free_shipping_en ) {
$free_shipping_min = $free_shipping_en;
}
echo $free_shipping_min;
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助某人。
| 归档时间: |
|
| 查看次数: |
3327 次 |
| 最近记录: |