gpt4 book ai didi

php - WooCommerce 2.1 检测选择的运输方式

转载 作者:可可西里 更新时间:2023-11-01 00:00:20 26 4
gpt4 key购买 nike

我一直在使用以下内容来决定结帐字段是否需要填写...

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com