huy*_*225 5 php wordpress shipping orders woocommerce
我曾尝试使用此答案中的代码:
如何在woocommerce中获得免费送货的最低订单金额
但它返回一个NULL结果,直到现在我找不到修复此代码的方法.
如何在结帐页面上获得正确的最小订单金额?
谢谢
这个答案的代码:How to get minimum order amount for free shipping in woocommerce 在 WooCommerce 2.6+ 版中
已经过时了,但它对这个功能性答案很有帮助......
在进行了一些搜索和一些尝试之后,我找到了获取特定区域(区域)在免费送货方式中设置的最低订单金额的方法:
这是工作测试代码(解释在里面注释):
// 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;
Run Code Online (Sandbox Code Playgroud)
答对了!你懂了。
| 归档时间: |
|
| 查看次数: |
882 次 |
| 最近记录: |