gpt4 book ai didi

php - 在 Woocommerce 中设置本地取 cargo 输方式的百分比折扣

转载 作者:行者123 更新时间:2023-12-01 11:16:00 25 4
gpt4 key购买 nike

我有一个使用 WooCommerce 插件的 WordPress 网站。如果买家选择本地取货作为运输方式,我想为他们提供购物车总额 5% 的折扣。

我已经试过了 - 5 * [数量] 它似乎不起作用。

我也试过 -0.95 * [cost] 没有运气

enter image description here
enter image description here

最佳答案

我正在使用 WooCommerce 3 并通过在事件主题的 function.php 中编写一个函数来实现上述结果。

function prefix_add_discount_line( $cart ) {
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping_no_ajax = $chosen_methods[0];
if ( 0 === strpos( $chosen_shipping_no_ajax, 'local_pickup' ) ) {

// Define the discount percentage
$discount = $cart->subtotal * 0.05;
// Add your discount note to cart
$cart->add_fee( __( 'Collection discount applied', 'yourtext-domain' ) , -$discount );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_discount_line');

关于php - 在 Woocommerce 中设置本地取 cargo 输方式的百分比折扣,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51171693/

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