Merge pull request #421 from lucasstark/patch-2

Added filter to coupon loading
This commit is contained in:
Mike Jolley 2011-12-23 11:28:51 -08:00
commit de77985713
1 changed files with 33 additions and 20 deletions

View File

@ -28,10 +28,24 @@ class woocommerce_coupon {
$this->code = $code; $this->code = $code;
$coupon_data = apply_filters('woocommerce_get_shop_coupon_data', false, $code);
if ($coupon_data) :
$this->id = $coupon_data['id'];
$this->type = $coupon_data['type'];
$this->amount = $coupon_data['amount'];
$this->individual_use = $coupon_data['individual_use'];
$this->product_ids = $coupon_data['product_ids'];
$this->exclude_product_ids = $coupon_data['exclude_product_ids'];
$this->usage_limit = $coupon_data['usage_limit'];
$this->usage_count = $coupon_data['usage_count'];
$this->expiry_date = $coupon_data['expiry_date'];
$this->apply_before_tax = $coupon_data['apply_before_tax'];
$this->free_shipping = $coupon_data['free_shipping'];
return true;
else:
$coupon = get_page_by_title($this->code, 'OBJECT', 'shop_coupon'); $coupon = get_page_by_title($this->code, 'OBJECT', 'shop_coupon');
if ($coupon && $coupon->post_status == 'publish') : if ($coupon && $coupon->post_status == 'publish') :
$this->id = $coupon->ID; $this->id = $coupon->ID;
$this->type = get_post_meta($coupon->ID, 'discount_type', true); $this->type = get_post_meta($coupon->ID, 'discount_type', true);
$this->amount = get_post_meta($coupon->ID, 'coupon_amount', true); $this->amount = get_post_meta($coupon->ID, 'coupon_amount', true);
@ -43,9 +57,8 @@ class woocommerce_coupon {
$this->expiry_date = ($expires = get_post_meta($coupon->ID, 'expiry_date', true)) ? strtotime($expires) : ''; $this->expiry_date = ($expires = get_post_meta($coupon->ID, 'expiry_date', true)) ? strtotime($expires) : '';
$this->apply_before_tax = get_post_meta($coupon->ID, 'apply_before_tax', true); $this->apply_before_tax = get_post_meta($coupon->ID, 'apply_before_tax', true);
$this->free_shipping = get_post_meta($coupon->ID, 'free_shipping', true); $this->free_shipping = get_post_meta($coupon->ID, 'free_shipping', true);
return true; return true;
endif;
endif; endif;
return false; return false;