installed plugin Easy Digital Downloads
version 3.1.0.3
This commit is contained in:
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/**
|
||||
* Adjustment Object.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Adjustments
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
namespace EDD\Adjustments;
|
||||
|
||||
use EDD\Base_Object;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Adjustment Class.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $parent
|
||||
* @property string $name
|
||||
* @property string $code
|
||||
* @property string $status
|
||||
* @property string $type
|
||||
* @property string $scope
|
||||
* @property string $amount_type
|
||||
* @property float $amount
|
||||
* @property string $description
|
||||
* @property int $max_uses
|
||||
* @property int $use_count
|
||||
* @property int $once_per_customer
|
||||
* @property float $min_charge_amount
|
||||
* @property string $start_date
|
||||
* @property string $end_date
|
||||
* @property string $date_created
|
||||
* @property string $date_modified
|
||||
*/
|
||||
class Adjustment extends Base_Object {
|
||||
|
||||
/**
|
||||
* ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Name.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Code.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* Status.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* Adjustment Type (discount, fee, tax, credit).
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Scope of the adjustment.
|
||||
*
|
||||
* global - Applies to all products in the cart, save for those explicitly excluded through excluded_products
|
||||
* not_global - Applies only to the products set in product_reqs
|
||||
*
|
||||
* This used to be called "is_not_global" but was changed to "scope" in 3.0.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
|
||||
/**
|
||||
* Adjustment Type (Percentage or Flat Amount).
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $amount_type;
|
||||
|
||||
/**
|
||||
* Adjustment Amount.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var mixed float|int
|
||||
*/
|
||||
protected $amount = null;
|
||||
|
||||
/**
|
||||
* Maximum Uses.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $max_uses = null;
|
||||
|
||||
/**
|
||||
* Use Count.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $use_count = null;
|
||||
|
||||
/**
|
||||
* Minimum Amount.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var mixed int|float
|
||||
*/
|
||||
protected $min_charge_amount;
|
||||
|
||||
/**
|
||||
* Is Single Use per customer?
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var bool
|
||||
*/
|
||||
protected $once_per_customer = null;
|
||||
|
||||
/**
|
||||
* Created Date.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $date_created;
|
||||
|
||||
/**
|
||||
* Start Date.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string|null
|
||||
*/
|
||||
protected $start_date = null;
|
||||
|
||||
/**
|
||||
* End Date.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string|null
|
||||
*/
|
||||
protected $end_date = null;
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Tax Rate Object.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Adjustments
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
namespace EDD\Adjustments;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Tax Rate Class.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $country
|
||||
* @property string $region
|
||||
*/
|
||||
class Tax_Rate extends Adjustment {
|
||||
|
||||
/**
|
||||
* ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Country.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $country;
|
||||
|
||||
/**
|
||||
* Region.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $region;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param mixed $object Object to populate members for.
|
||||
*/
|
||||
public function __construct( $object = null ) {
|
||||
parent::__construct( $object );
|
||||
|
||||
$this->country = $this->name;
|
||||
$this->region = $this->description;
|
||||
}
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
/**
|
||||
* Adjustment Functions.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Adjustments
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Add an adjustment.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $data {
|
||||
* Array of adjustment data. Default empty.
|
||||
*
|
||||
* The `date_created` and `date_modified` parameters do not need to be passed.
|
||||
* They will be automatically populated if empty.
|
||||
*
|
||||
* @type int $parent Parent adjustment ID. Default empty.
|
||||
* @type string $name Name of the adjustment. Default empty.
|
||||
* @type string $code Code that needs to be applied at the
|
||||
* checkout for the adjustment to be applied.
|
||||
* @type string $status Adjustment status. Default `draft`.
|
||||
* @type string $type Adjustment type (e.g. `discount`). Default empty.
|
||||
* @type string $scope Adjustment scope. Value is dependent on
|
||||
* the adjustment type. E.g. a tax rate will
|
||||
* a scope of `country` or `region`. Default empty.
|
||||
* @type string $amount_type Type of adjustment. Adjustments can be a
|
||||
* percentage or a flat amount. Default empty.
|
||||
* @type float $amount Adjustment amount. If the amount type is a,
|
||||
* percentage the amount reflects a percentage,
|
||||
* otherwise a flat amount.
|
||||
* @type string $description Extended description of an adjustment.
|
||||
* Default empty.
|
||||
* @type int $max_uses Maximum number of times an adjustment can
|
||||
* be used. Default 0 (unlimited).
|
||||
* @type int $use_count Usage count of the adjustment. Default 0.
|
||||
* @type bool $once_per_customer True if customer can only apply adjustment
|
||||
* once, false otherwise. Default false.
|
||||
* @type float $min_charge_amount Minimum amount that needs to be in the cart
|
||||
* for adjustment to be valid. Default 0.
|
||||
* @type string $product_condition Product condition that needs to hold for
|
||||
* adjustment to be valid. Default empty.
|
||||
* @type string|null $start_date The date & time the adjustment is valid from.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default null.
|
||||
* @type string|null $end_date The date & time the adjustment is valid to.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default null.
|
||||
* @type string $date_created Optional. Automatically calculated on add/edit.
|
||||
* The date & time the adjustment was inserted.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* @type string $date_modified Optional. Automatically calculated on add/edit.
|
||||
* The date & time the adjustment was last modified.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* }
|
||||
* @return int ID of the inserted adjustment.
|
||||
*/
|
||||
function edd_add_adjustment( $data = array() ) {
|
||||
$adjustments = new EDD\Database\Queries\Adjustment();
|
||||
|
||||
return $adjustments->add_item( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an adjustment.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $adjustment_id Adjustment ID.
|
||||
* @return int|false `1` if the adjustment was deleted successfully, false on error.
|
||||
*/
|
||||
function edd_delete_adjustment( $adjustment_id = 0 ) {
|
||||
$adjustments = new EDD\Database\Queries\Adjustment();
|
||||
|
||||
return $adjustments->delete_item( $adjustment_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an adjustment.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $adjustment_id Adjustment ID.
|
||||
* @param array $data {
|
||||
* Array of adjustment data. Default empty.
|
||||
*
|
||||
* @type int $parent Parent adjustment ID. Default empty.
|
||||
* @type string $name Name of the adjustment. Default empty.
|
||||
* @type string $code Code that needs to be applied at the
|
||||
* checkout for the adjustment to be applied.
|
||||
* @type string $status Adjustment status. Default `draft`.
|
||||
* @type string $type Adjustment type (e.g. `discount`). Default empty.
|
||||
* @type string $scope Adjustment scope. Value is dependent on
|
||||
* the adjustment type. E.g. a tax rate will
|
||||
* a scope of `country` or `region`. Default empty.
|
||||
* @type string $amount_type Type of adjustment. Adjustments can be a
|
||||
* percentage or a flat amount. Default empty.
|
||||
* @type float $amount Adjustment amount. If the amount type is a,
|
||||
* percentage the amount reflects a percentage,
|
||||
* otherwise a flat amount.
|
||||
* @type string $description Extended description of an adjustment.
|
||||
* Default empty.
|
||||
* @type int $max_uses Maximum number of times an adjustment can
|
||||
* be used. Default 0 (unlimited).
|
||||
* @type int $use_count Usage count of the adjustment. Default 0.
|
||||
* @type bool $once_per_customer True if customer can only apply adjustment
|
||||
* once, false otherwise. Default false.
|
||||
* @type float $min_charge_amount Minimum amount that needs to be in the cart
|
||||
* for adjustment to be valid. Default 0.
|
||||
* @type string $product_condition Product condition that needs to hold for
|
||||
* adjustment to be valid. Default empty.
|
||||
* @type string|null $start_date The date & time the adjustment is valid from.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* @type string|null $end_date The date & time the adjustment is valid to.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* @type string $date_created Optional. Automatically calculated on add/edit.
|
||||
* The date & time the adjustment was inserted.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* @type string $date_modified Optional. Automatically calculated on add/edit.
|
||||
* The date & time the adjustment was last modified.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* }
|
||||
*
|
||||
* @return int|false Number of rows updated if successful, false otherwise.
|
||||
*/
|
||||
function edd_update_adjustment( $adjustment_id = 0, $data = array() ) {
|
||||
$adjustments = new EDD\Database\Queries\Adjustment();
|
||||
|
||||
return $adjustments->update_item( $adjustment_id, $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an adjustment by ID.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $adjustment_id Adjustment ID.
|
||||
* @return EDD\Adjustments\Adjustment|false Adjustment object if successful,
|
||||
* false otherwise.
|
||||
*/
|
||||
function edd_get_adjustment( $adjustment_id = 0 ) {
|
||||
$adjustments = new EDD\Database\Queries\Adjustment();
|
||||
|
||||
// Return adjustment
|
||||
return $adjustments->get_item( $adjustment_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an adjustment by a specific field value.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $field Database table field.
|
||||
* @param string $value Value of the row.
|
||||
*
|
||||
* @return EDD\Adjustments\Adjustment|false Adjustment object if successful,
|
||||
* false otherwise.
|
||||
*/
|
||||
function edd_get_adjustment_by( $field = '', $value = '' ) {
|
||||
$adjustments = new EDD\Database\Queries\Adjustment();
|
||||
|
||||
// Return adjustment
|
||||
return $adjustments->get_item_by( $field, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for adjustments.
|
||||
*
|
||||
* @see \EDD\Database\Queries\Adjustment::__construct()
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $args Arguments. See `EDD\Database\Queries\Adjustment` for
|
||||
* accepted arguments.
|
||||
* @return \EDD\Adjustments\Adjustment[] Array of `Adjustment` objects.
|
||||
*/
|
||||
function edd_get_adjustments( $args = array() ) {
|
||||
|
||||
// Parse args
|
||||
$r = wp_parse_args( $args, array(
|
||||
'number' => 30
|
||||
) );
|
||||
|
||||
// Instantiate a query object
|
||||
$adjustments = new EDD\Database\Queries\Adjustment();
|
||||
|
||||
// Return adjustments
|
||||
return $adjustments->query( $r );
|
||||
}
|
||||
|
||||
/**
|
||||
* Count adjustments.
|
||||
*
|
||||
* @see \EDD\Database\Queries\Adjustment::__construct()
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $args Arguments. See `EDD\Database\Queries\Adjustment` for
|
||||
* accepted arguments.
|
||||
* @return int Number of adjustments returned based on query arguments passed.
|
||||
*/
|
||||
function edd_count_adjustments( $args = array() ) {
|
||||
|
||||
// Parse args
|
||||
$r = wp_parse_args( $args, array(
|
||||
'count' => true
|
||||
) );
|
||||
|
||||
// Query for count(s)
|
||||
$adjustments = new EDD\Database\Queries\Adjustment( $r );
|
||||
|
||||
// Return count(s)
|
||||
return absint( $adjustments->found_items );
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Adjustment Meta Functions
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Adjustments
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Add meta data field to a adjustment.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $adjustment_id Adjustment ID.
|
||||
* @param string $meta_key Meta data name.
|
||||
* @param mixed $meta_value Meta data value. Must be serializable if non-scalar.
|
||||
* @param bool $unique Optional. Whether the same key should not be added. Default false.
|
||||
*
|
||||
* @return int|false Meta ID on success, false on failure.
|
||||
*/
|
||||
function edd_add_adjustment_meta( $adjustment_id, $meta_key, $meta_value, $unique = false ) {
|
||||
return add_metadata( 'edd_adjustment', $adjustment_id, $meta_key, $meta_value, $unique );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove meta data matching criteria from a adjustment.
|
||||
*
|
||||
* You can match based on the key, or key and value. Removing based on key and value, will keep from removing duplicate
|
||||
* meta data with the same key. It also allows removing all meta data matching key, if needed.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $adjustment_id Adjustment ID.
|
||||
* @param string $meta_key Meta data name.
|
||||
* @param mixed $meta_value Optional. Meta data value. Must be serializable if non-scalar. Default empty.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
function edd_delete_adjustment_meta( $adjustment_id, $meta_key, $meta_value = '' ) {
|
||||
return delete_metadata( 'edd_adjustment', $adjustment_id, $meta_key, $meta_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve adjustment meta field for a adjustment.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $adjustment_id Adjustment ID.
|
||||
* @param string $key Optional. The meta key to retrieve. By default, returns data for all keys. Default empty.
|
||||
* @param bool $single Optional, default is false. If true, return only the first value of the specified meta_key.
|
||||
* This parameter has no effect if meta_key is not specified.
|
||||
*
|
||||
* @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true.
|
||||
*/
|
||||
function edd_get_adjustment_meta( $adjustment_id, $key = '', $single = false ) {
|
||||
return get_metadata( 'edd_adjustment', $adjustment_id, $key, $single );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update adjustment meta field based on adjustment ID.
|
||||
*
|
||||
* Use the $prev_value parameter to differentiate between meta fields with the
|
||||
* same key and adjustment ID.
|
||||
*
|
||||
* If the meta field for the adjustment does not exist, it will be added.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $adjustment_id Adjustment ID.
|
||||
* @param string $meta_key Meta data key.
|
||||
* @param mixed $meta_value Meta data value. Must be serializable if non-scalar.
|
||||
* @param mixed $prev_value Optional. Previous value to check before removing. Default empty.
|
||||
*
|
||||
* @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
|
||||
*/
|
||||
function edd_update_adjustment_meta( $adjustment_id, $meta_key, $meta_value, $prev_value = '' ) {
|
||||
return update_metadata( 'edd_adjustment', $adjustment_id, $meta_key, $meta_value, $prev_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete everything from adjustment meta matching meta key.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $meta_key Key to search for when deleting.
|
||||
*
|
||||
* @return bool Whether the adjustment meta key was deleted from the database.
|
||||
*/
|
||||
function edd_delete_adjustment_meta_by_key( $meta_key ) {
|
||||
return delete_metadata( 'edd_adjustment', null, $meta_key, '', true );
|
||||
}
|
Reference in New Issue
Block a user