PHP Class WC_API_Coupons

Inheritance: extends WC_API_Resource
Show file Open project: woocommerce/woocommerce

Protected Properties

Property Type Description
$base string the route base

Public Methods

Method Description
bulk ( array $data ) : array Bulk update or insert coupons Accepts an array with coupons in the formats supported by WC_API_Coupons->create_coupon() and WC_API_Coupons->edit_coupon()
create_coupon ( array $data ) : array Create a coupon
delete_coupon ( integer $id, boolean $force = false ) : array Delete a coupon
edit_coupon ( integer $id, array $data ) : array Edit a coupon
get_coupon ( integer $id, string $fields = null ) : array | WP_Error Get the coupon for the given ID
get_coupon_by_code ( string $code, string $fields = null ) : integer | WP_Error Get the coupon for the given code
get_coupons ( string $fields = null, array $filter = [], integer $page = 1 ) : array Get all coupons
get_coupons_count ( array $filter = [] ) : array Get the total number of coupons
register_routes ( array $routes ) : array Register the routes for this class

Protected Methods

Method Description
get_coupon_expiry_date ( string $expiry_date ) : string expiry_date format

Private Methods

Method Description
query_coupons ( array $args ) : WP_Query Helper method to get coupon post objects

Method Details

bulk() public method

Bulk update or insert coupons Accepts an array with coupons in the formats supported by WC_API_Coupons->create_coupon() and WC_API_Coupons->edit_coupon()
Since: 2.4.0
public bulk ( array $data ) : array
$data array
return array

create_coupon() public method

Create a coupon
Since: 2.2
public create_coupon ( array $data ) : array
$data array
return array

delete_coupon() public method

Delete a coupon
Since: 2.2
public delete_coupon ( integer $id, boolean $force = false ) : array
$id integer the coupon ID
$force boolean true to permanently delete coupon, false to move to trash
return array

edit_coupon() public method

Edit a coupon
Since: 2.2
public edit_coupon ( integer $id, array $data ) : array
$id integer the coupon ID
$data array
return array

get_coupon() public method

Get the coupon for the given ID
Since: 2.1
public get_coupon ( integer $id, string $fields = null ) : array | WP_Error
$id integer the coupon ID
$fields string fields to include in response
return array | WP_Error

get_coupon_by_code() public method

Get the coupon for the given code
Since: 2.1
public get_coupon_by_code ( string $code, string $fields = null ) : integer | WP_Error
$code string the coupon code
$fields string fields to include in response
return integer | WP_Error

get_coupon_expiry_date() protected method

expiry_date format
Since: 2.3.0
protected get_coupon_expiry_date ( string $expiry_date ) : string
$expiry_date string
return string

get_coupons() public method

Get all coupons
Since: 2.1
public get_coupons ( string $fields = null, array $filter = [], integer $page = 1 ) : array
$fields string
$filter array
$page integer
return array

get_coupons_count() public method

Get the total number of coupons
Since: 2.1
public get_coupons_count ( array $filter = [] ) : array
$filter array
return array

register_routes() public method

GET /coupons GET /coupons/count GET /coupons/
Since: 2.1
public register_routes ( array $routes ) : array
$routes array
return array

Property Details

$base protected property

the route base
protected string $base
return string