是否有一个挂钩或插件可以从woocommerce优惠券中排除某些产品标签?

时间:2019-04-16 18:18:42

标签: php wordpress woocommerce coupon

我需要从woocommerce优惠券中排除产品标签。

我曾尝试在Google上搜索适用的插件,但出现空白。

理想情况下,一种解决方案是将插件添加到优惠券帖子类型的自定义字段。但是,我将通过挂钩/过滤器解决硬编码问题。

1 个答案:

答案 0 :(得分:1)

There is a filter you can use to accomplish this woocommerce_coupon_is_valid_for_product.

It accepts 4 parameters, valid, the product, the coupon and values. It's called from class-wc-coupon.php around line 860 in version 3 or so. It should return a boolean (true/false).

Note that the code below is incomplete and untested, and is for example purposes only.

add_filter('woocommerce_coupon_is_valid_for_product', 'exclude_product_from_coupon_by_tag', 12, 4);
function exclude_product_from_coupon_by_tag($valid, $product, $coupon, $values ){

    //Check if product has tag/s
    $valid = has_term('INSERT_TERM_HERE', 'product_tag');

    return $valid;
}

Hope that helps!