在结帐页面中获取“免费送货"方法的最低订单金额 [英] Getting minimum order amount for 'Free Shipping' method in checkout page

查看:46
本文介绍了在结帐页面中获取“免费送货"方法的最低订单金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实尝试使用此答案中的代码:

这是经过测试的工作代码(里面有注释):

//这里你得到(正如你已经知道的)使用的运输方式参考$chosen_methods = WC()->session->get('chosen_shipping_methods');//将字符串 ':' 替换为 '_'$option_value = str_replace(':', '_', $chosen_methods[0]);//我们将字符串与其他子字符串连接起来$option_value = 'woocommerce_'.$option_value.'_settings';//只是一个测试 =>输出字符串看看我们得到了什么回声 $option_value;回声'<br>';//现在我们可以使用该格式化字符串获取选项值$free_shipping_settings = get_option( $option_value );//仅用于测试 =>我们输出(预先格式化的)值数组来检查echo '

';打印_r($free_shipping_settings);echo '</pre><br>';//这里我们得到订单最小金额的值(终于!)$order_min_amount = $free_shipping_settings['min_amount'];//我们输出值(检查)echo '订单最小金额:'.$order_min_amount;

宾果游戏!你懂的.

I have did tried to use the code from this answer:
How to get minimum order amount for free shipping in woocommerce

But it return a NULL result and I can't find the way to fix this code until now.

How can I get the right minimun order amount on checkout page?

Thanks

解决方案

The code of this answer: How to get minimum order amount for free shipping in woocommerce
is obsolete with WooCommerce version 2.6+, but it was helpful for this functional answer…

After making some search and some tries, I have found the way to get the minimum Order amount that is set in the Free Shipping method, for a specific Zone (Region):

Here is the working tested code (explanations are commented inside):

// Here you get (as you already know) the used shipping method reference
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );

// Replacing inside the string ':' by '_'
$option_value = str_replace(':', '_', $chosen_methods[0]);

// We concatenate the string with additional sub-strings
$option_value = 'woocommerce_'.$option_value.'_settings';

// Just a test => outputting the string to see what we get
echo $option_value; echo '<br>';

// Now we can get the options values with that formatted string
$free_shipping_settings = get_option( $option_value );

// Just for test => we output the (pre-formatted) array of values to check
echo '<pre>'; print_r($free_shipping_settings); echo '</pre><br>'; 

// Here we get the value of the order min amount (Finally!)
$order_min_amount = $free_shipping_settings['min_amount'];

// We output the value (to check)
echo 'Order min amount: '.$order_min_amount;

Bingo! you get it.

这篇关于在结帐页面中获取“免费送货"方法的最低订单金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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