我一直在使用以下内容来决定结帐字段是否需要填写...
if ($posted['shipping_method'] == "local_pickup_plus") {
}
自从更新到 WooCommerce 2.1 后,我的代码不再有效。
我尝试回显存储在 $posted['shipping_method'] 中的值,看看我是否在根据正确的值检查它,但似乎此变量中不再存储任何内容。
我一直在寻找其他方法来检查所选的送货方式,但我没有取得太大进展。
如有任何帮助,我们将不胜感激。
最佳答案
找了几个小时,然后决定深入研究 WooCommerce 文件...
这似乎对我有用:
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
我通过在我的 functions.php 中像这样使用它来设置本地交付的最小总数
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
$min_spend = 25;
$cart_total = $woocommerce->cart->cart_contents_total;
if (($cart_total < 25) AND ($chosen_shipping == 'local_delivery')) {
$surcharge = $min_spend-$cart_total;
$woocommerce->cart->add_fee( 'Delivery Surchage', $surcharge, true, 'standard' );
}
}
希望这对某人有所帮助。
关于php - WooCommerce 2.1 检测选择的运输方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22383621/