我也没有试图从这个答案使用代码:
How to get minimum order amount for free shipping in woocommerce获得了“免费送货”的方法最低订货量在结账页面
但它返回一个NULL
结果,我无法找到到目前为止修复此代码的方法。
我怎样才能在结帐页面上获得最低订单金额?
感谢
我也没有试图从这个答案使用代码:
How to get minimum order amount for free shipping in 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;
宾果!你懂了。
你需要先得到它得到的选项,
get_option('woocommerce_free_shipping_1_settings');
然后反序列化,通过执行数据,
maybe_unserialize();
谢谢你的回答。我的数据库有太多** woocommerce_free_shipping_x_settings **(使用x:9-> 19)。我想在结帐页面中获得最低金额的免运费方式。你明白这个问题吗?请帮我 – huykon225
也许它会帮助别人。您可以创建新的免费送货对象并从中获取min_amount。我认为这比@LoicTheAztec的答案简单。
if (class_exists('WC_Shipping_Free_Shipping')) {
$free_shipping = new WC_Shipping_Free_Shipping();
$min_amount = $free_shipping->min_amount;
echo $min_amount;
}
它不适用于woocommerce 2.6或更高。请在发送您的答案之前检查? – huykon225
的可能的复制[如何获得在woocommerce免费送货的最低订单金额(http://stackoverflow.com/questions/26582039/how-to-get-minimum-order-amount-for-free -shocom-in-woocommerce) –
请再读一遍我的描述。我有这样做(你的链接),但它返回NULL结果。我这样做: $ chosen_methods = WC() - > session-> get('chosen_shipping_methods'); \t \t $ chosen_shipping = $ chosen_methods [0]; 但如何选择方法是免费送货我可以得到min_amount? – huykon225
@LoicTheAztec你的意思是我必须改变问题或描述? 所有我想要的东西:当我来结账页面,并选择了一种运输方式是免费送货,我想**这种方法的**最低金额**。你可以帮我吗 ? – huykon225