获取最低订单金额 'Free Shipping'结帐页面中的方法 [英] Getting minimum order amount for 'Free Shipping' method in checkout page
问题描述
我确实尝试使用此答案中的代码:
这是经过测试的工作代码(里面有注释):
//这里你得到(正如你已经知道的)使用的运输方式参考$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.
这篇关于获取最低订单金额 &#39;Free Shipping&#39;结帐页面中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!