小编Den*_*ith的帖子

具有自定义折扣的Woocommerce自定义优惠券类型始终返回0;

我想要做的是创建自定义优惠券类型与使用钩子的woocommerce自定义编程折扣.这就是我的代码

//add new coupon type called "custom_discount"
function custom_discount_type( $discount_types ) {
    $discount_types['custom_discount'] =__( 'custom discount', 'woocommerce' );
    return $discount_types;
    }

// add the hooks
add_filter( 'woocommerce_coupon_discount_types', 'custom_discount_type',10, 1);

//function to get coupon amount for "custom_discount"
function woocommerce_coupon_get_discount_amount($discount, $discounting_amount, $cart_item, $single, $coupon) {
        if ($coupon->type == 'custom_discount'){ //if $coupon->type == 'fixed_cart' or 'percent' or 'fixed_product' or 'percent_product' The code Works
            $discount = 85;
            return $discount;
            } else {
             return $discount;
            }
        }
//add hook to coupon amount hook
add_filter('woocommerce_coupon_get_discount_amount', 'woocommerce_coupon_get_discount_amount', …
Run Code Online (Sandbox Code Playgroud)

wordpress woocommerce

2
推荐指数
1
解决办法
3161
查看次数

标签 统计

woocommerce ×1

wordpress ×1