2016-02-23 16:01:40 +00:00
|
|
|
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
2016-02-25 16:10:49 +00:00
|
|
|
exit;
|
2016-02-23 16:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-08 19:17:10 +00:00
|
|
|
* Legacy Coupon.
|
2016-02-23 16:01:40 +00:00
|
|
|
*
|
|
|
|
* Legacy and deprecated functions are here to keep the WC_Legacy_Coupon class clean.
|
|
|
|
* This class will be removed in future versions.
|
|
|
|
*
|
|
|
|
* @class WC_Legacy_Coupon
|
2017-03-15 16:36:53 +00:00
|
|
|
* @version 3.0.0
|
2016-02-23 16:01:40 +00:00
|
|
|
* @package WooCommerce/Classes
|
|
|
|
* @category Class
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
2016-03-17 16:38:56 +00:00
|
|
|
abstract class WC_Legacy_Coupon extends WC_Data {
|
2016-02-23 16:01:40 +00:00
|
|
|
|
|
|
|
/**
|
2016-02-25 16:10:49 +00:00
|
|
|
* Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past.
|
2016-02-23 16:01:40 +00:00
|
|
|
* @param string $key
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function __isset( $key ) {
|
2016-02-25 16:10:49 +00:00
|
|
|
$legacy_keys = array(
|
2016-08-27 03:04:10 +00:00
|
|
|
'id',
|
|
|
|
'exists',
|
|
|
|
'coupon_custom_fields',
|
|
|
|
'type',
|
|
|
|
'discount_type',
|
|
|
|
'amount',
|
2017-03-09 18:34:45 +00:00
|
|
|
'coupon_amount',
|
2016-08-27 03:04:10 +00:00
|
|
|
'code',
|
|
|
|
'individual_use',
|
|
|
|
'product_ids',
|
|
|
|
'exclude_product_ids',
|
|
|
|
'usage_limit',
|
|
|
|
'usage_limit_per_user',
|
|
|
|
'limit_usage_to_x_items',
|
|
|
|
'usage_count',
|
|
|
|
'expiry_date',
|
|
|
|
'product_categories',
|
|
|
|
'exclude_product_categories',
|
|
|
|
'minimum_amount',
|
|
|
|
'maximum_amount',
|
|
|
|
'customer_email',
|
2016-02-25 16:10:49 +00:00
|
|
|
);
|
|
|
|
if ( in_array( $key, $legacy_keys ) ) {
|
2016-02-23 16:01:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-02-25 16:10:49 +00:00
|
|
|
* Magic __get method for backwards compatibility. Maps legacy vars to new getters.
|
2016-02-23 16:01:40 +00:00
|
|
|
* @param string $key
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __get( $key ) {
|
2017-03-15 16:36:53 +00:00
|
|
|
wc_doing_it_wrong( $key, 'Coupon properties should not be accessed directly.', '3.0' );
|
2016-02-25 16:10:49 +00:00
|
|
|
|
2016-08-27 04:23:02 +00:00
|
|
|
switch ( $key ) {
|
2016-02-25 16:36:39 +00:00
|
|
|
case 'id' :
|
|
|
|
$value = $this->get_id();
|
|
|
|
break;
|
2016-02-25 16:10:49 +00:00
|
|
|
case 'exists' :
|
2018-03-21 22:57:10 +00:00
|
|
|
$value = $this->get_id() > 0;
|
2016-02-25 16:10:49 +00:00
|
|
|
break;
|
|
|
|
case 'coupon_custom_fields' :
|
2016-03-08 17:46:26 +00:00
|
|
|
$legacy_custom_fields = array();
|
2016-03-17 16:38:56 +00:00
|
|
|
$custom_fields = $this->get_id() ? $this->get_meta_data() : array();
|
2016-03-08 17:46:26 +00:00
|
|
|
if ( ! empty( $custom_fields ) ) {
|
2016-03-17 18:14:15 +00:00
|
|
|
foreach ( $custom_fields as $cf_value ) {
|
|
|
|
// legacy only supports 1 key
|
|
|
|
$legacy_custom_fields[ $cf_value->key ][0] = $cf_value->value;
|
2016-03-08 17:46:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$value = $legacy_custom_fields;
|
2016-02-25 16:10:49 +00:00
|
|
|
break;
|
|
|
|
case 'type' :
|
|
|
|
case 'discount_type' :
|
|
|
|
$value = $this->get_discount_type();
|
|
|
|
break;
|
|
|
|
case 'amount' :
|
2017-03-09 18:34:45 +00:00
|
|
|
case 'coupon_amount' :
|
2016-02-25 16:10:49 +00:00
|
|
|
$value = $this->get_amount();
|
|
|
|
break;
|
|
|
|
case 'code' :
|
|
|
|
$value = $this->get_code();
|
|
|
|
break;
|
|
|
|
case 'individual_use' :
|
2016-02-25 16:36:39 +00:00
|
|
|
$value = ( true === $this->get_individual_use() ) ? 'yes' : 'no';
|
2016-02-25 16:10:49 +00:00
|
|
|
break;
|
|
|
|
case 'product_ids' :
|
|
|
|
$value = $this->get_product_ids();
|
|
|
|
break;
|
|
|
|
case 'exclude_product_ids' :
|
|
|
|
$value = $this->get_excluded_product_ids();
|
|
|
|
break;
|
|
|
|
case 'usage_limit' :
|
|
|
|
$value = $this->get_usage_limit();
|
|
|
|
break;
|
|
|
|
case 'usage_limit_per_user' :
|
|
|
|
$value = $this->get_usage_limit_per_user();
|
|
|
|
break;
|
|
|
|
case 'limit_usage_to_x_items' :
|
|
|
|
$value = $this->get_limit_usage_to_x_items();
|
|
|
|
break;
|
|
|
|
case 'usage_count' :
|
|
|
|
$value = $this->get_usage_count();
|
|
|
|
break;
|
|
|
|
case 'expiry_date' :
|
2017-03-15 15:19:17 +00:00
|
|
|
$value = ( $this->get_date_expires() ? $this->get_date_expires()->date( 'Y-m-d' ) : '' );
|
2016-02-25 16:10:49 +00:00
|
|
|
break;
|
|
|
|
case 'product_categories' :
|
|
|
|
$value = $this->get_product_categories();
|
|
|
|
break;
|
|
|
|
case 'exclude_product_categories' :
|
|
|
|
$value = $this->get_excluded_product_categories();
|
|
|
|
break;
|
|
|
|
case 'minimum_amount' :
|
|
|
|
$value = $this->get_minimum_amount();
|
|
|
|
break;
|
|
|
|
case 'maximum_amount' :
|
|
|
|
$value = $this->get_maximum_amount();
|
|
|
|
break;
|
|
|
|
case 'customer_email' :
|
|
|
|
$value = $this->get_email_restrictions();
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
$value = '';
|
|
|
|
break;
|
2016-02-23 16:01:40 +00:00
|
|
|
}
|
2016-02-25 16:10:49 +00:00
|
|
|
|
2016-02-23 16:01:40 +00:00
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format loaded data as array.
|
|
|
|
* @param string|array $array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function format_array( $array ) {
|
2017-03-23 15:32:02 +00:00
|
|
|
wc_deprecated_function( 'WC_Coupon::format_array', '3.0' );
|
2016-02-23 16:01:40 +00:00
|
|
|
if ( ! is_array( $array ) ) {
|
|
|
|
if ( is_serialized( $array ) ) {
|
|
|
|
$array = maybe_unserialize( $array );
|
|
|
|
} else {
|
|
|
|
$array = explode( ',', $array );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array_filter( array_map( 'trim', array_map( 'strtolower', $array ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if coupon needs applying before tax.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function apply_before_tax() {
|
2017-03-23 15:32:02 +00:00
|
|
|
wc_deprecated_function( 'WC_Coupon::apply_before_tax', '3.0' );
|
2016-02-23 16:01:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a coupon enables free shipping.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function enable_free_shipping() {
|
2017-03-23 15:32:02 +00:00
|
|
|
wc_deprecated_function( 'WC_Coupon::enable_free_shipping', '3.0', 'WC_Coupon::get_free_shipping' );
|
2016-02-25 16:36:39 +00:00
|
|
|
return $this->get_free_shipping();
|
2016-02-23 16:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a coupon excludes sale items.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function exclude_sale_items() {
|
2017-03-23 15:32:02 +00:00
|
|
|
wc_deprecated_function( 'WC_Coupon::exclude_sale_items', '3.0', 'WC_Coupon::get_exclude_sale_items' );
|
2016-02-25 16:36:39 +00:00
|
|
|
return $this->get_exclude_sale_items();
|
2016-02-23 16:01:40 +00:00
|
|
|
}
|
2016-11-09 12:21:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increase usage count for current coupon.
|
|
|
|
*
|
|
|
|
* @param string $used_by Either user ID or billing email
|
|
|
|
*/
|
|
|
|
public function inc_usage_count( $used_by = '' ) {
|
|
|
|
$this->increase_usage_count( $used_by );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrease usage count for current coupon.
|
|
|
|
*
|
|
|
|
* @param string $used_by Either user ID or billing email
|
|
|
|
*/
|
|
|
|
public function dcr_usage_count( $used_by = '' ) {
|
|
|
|
$this->decrease_usage_count( $used_by );
|
|
|
|
}
|
2016-02-23 16:01:40 +00:00
|
|
|
}
|