gpt4 book ai didi

php - Woocommerce - 在产品页面上获取运费

转载 作者:搜寻专家 更新时间:2023-10-31 20:34:52 24 4
gpt4 key购买 nike

我使用的是 Wordpress 3.9.14。

我使用 flat_rate我的运费方法。
它包含默认 cost_per_order我用 2 shipping_classes里面flat_rate某些产品的额外费用。

我想在产品页面上显示运费。
现在我使用 $product->shipping_class_id()获取 ID,但我不知道如何获取此 shipping_class_id 的费用。
因为如果我知道成本,我可以将其添加到 cost_per_order计算产品的总运费。

我也不知道如何获得 cost_per_order值(value)。

如果根本没有解决方案,我可以使用 switch/case 作为紧急解决方案声明并将成本放在那里但是当我更改 flat_rate 时我需要更改代码成本,所以我不喜欢这种解决方案。

最佳答案

我想通了:

$shipping_class_id = $product->get_shipping_class_id();
$shipping_class= $product->get_shipping_class();
$fee = 0;

if ($shipping_class_id) {
$flat_rates = get_option("woocommerce_flat_rates");
$fee = $flat_rates[$shipping_class]['cost'];
}

$flat_rate_settings = get_option("woocommerce_flat_rate_settings");
echo 'Shipping cost: ' . ($flat_rate_settings['cost_per_order'] + $fee);

关于php - Woocommerce - 在产品页面上获取运费,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40279590/

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