is_valid功能核心代码如何删除is_valid
功能$this->validate_product_categories();
在WooCommerce class-wc-coupon.php
文件,而无需编辑插件?旁路validate_product_categories()在类WC_Coupon
在functions.php中有这样做的钩子吗?
这里是class-wc-coupon.php
的源代码:
/**
* Check if a coupon is valid.
*
* @return boolean validity
* @throws Exception
*/
public function is_valid() {
try {
$this->validate_exists();
$this->validate_usage_limit();
$this->validate_user_usage_limit();
$this->validate_expiry_date();
$this->validate_minimum_amount();
$this->validate_maximum_amount();
$this->validate_product_ids();
$this->validate_product_categories();
$this->validate_sale_items();
$this->validate_excluded_items();
$this->validate_cart_excluded_items();
if (! apply_filters('woocommerce_coupon_is_valid', true, $this)) {
throw new Exception(self::E_WC_COUPON_INVALID_FILTERED);
}
} catch (Exception $e) {
echo $this->error_message = $this->get_coupon_error($e->getMessage());
return false;
}
return true;
}
感谢
为什么要删除它?你可以更新插件,并检查是否有任何问题,并可以联系支持论坛的问题。强烈推荐。 –
回到你的问题的解决方案,在你的* functions.php *我想你需要覆盖这个功能。像这样的http://hookr.io/filters/woocommerce_coupon_is_valid/不知道。 –
也检查这一次http://stackoverflow.com/questions/21397325/want-to-overwrite-functions-written-in-woocommerce-functions-php-file –