如何在 WooCommerce 中获得最低的统一运费
How to get the lowest FLAT RATE shipping cost in WooCommerce
我想要的很简单:我想在 WooCommerce 的产品页面上显示最低统一费率运费,这样我就可以显示:"We already deliver orders from € ..."。
客户所在国家/地区的哪个航运区处于活动状态并不重要...我只需要可用的整体(静态)最低统一费率成本。
到目前为止我有这个:
foreach ((array) $delivery_zones as $key => $delivery_zone ) {
$shipping_costs = [];
foreach ($delivery_zone['shipping_methods'] as $value) {
$shipping_costs[] = $value->cost;
break;
}
echo (min($shipping_costs));
}
但这仍然会输出所有固定费率成本 f.i。: 1,99 3,99 5,99
如何只显示最低(在本例中为 1,99)费率?
很多 tnx!
我认为这是一个简单的错误,请试试这个:
function get_lowest_shipping_flat_rate_1()
{
$delivery_zones = WC_Shipping_Zones::get_zones();
//define the array outside of the loop
$shipping_costs = [];
$min_zone = "";
//get all costs in a loop and store them in the array
foreach ((array) $delivery_zones as $key => $the_zone ) {
foreach ($the_zone['shipping_methods'] as $value) {
$shipping_costs[] = $value->cost;
if(min($shipping_costs) == $value->cost) $min_zone = $the_zone['zone_name'];
}
}
$content = $min_zone . " - " . get_woocommerce_currency_symbol() . " " . min($shipping_costs);
return $content;
}
我想要的很简单:我想在 WooCommerce 的产品页面上显示最低统一费率运费,这样我就可以显示:"We already deliver orders from € ..."。
客户所在国家/地区的哪个航运区处于活动状态并不重要...我只需要可用的整体(静态)最低统一费率成本。
到目前为止我有这个:
foreach ((array) $delivery_zones as $key => $delivery_zone ) {
$shipping_costs = [];
foreach ($delivery_zone['shipping_methods'] as $value) {
$shipping_costs[] = $value->cost;
break;
}
echo (min($shipping_costs));
}
但这仍然会输出所有固定费率成本 f.i。: 1,99 3,99 5,99
如何只显示最低(在本例中为 1,99)费率?
很多 tnx!
我认为这是一个简单的错误,请试试这个:
function get_lowest_shipping_flat_rate_1()
{
$delivery_zones = WC_Shipping_Zones::get_zones();
//define the array outside of the loop
$shipping_costs = [];
$min_zone = "";
//get all costs in a loop and store them in the array
foreach ((array) $delivery_zones as $key => $the_zone ) {
foreach ($the_zone['shipping_methods'] as $value) {
$shipping_costs[] = $value->cost;
if(min($shipping_costs) == $value->cost) $min_zone = $the_zone['zone_name'];
}
}
$content = $min_zone . " - " . get_woocommerce_currency_symbol() . " " . min($shipping_costs);
return $content;
}