Setters
This commit is contained in:
parent
b1bd1c2227
commit
2636d04ba6
|
@ -582,25 +582,30 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
* Set order ID.
|
||||
* @since 2.7.0
|
||||
* @param int $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_id( $value ) {
|
||||
$this->_data['id'] = absint( $value );
|
||||
return $this->set_prop( 'id', absint( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parent order ID.
|
||||
* @since 2.7.0
|
||||
* @param int $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_parent_id( $value ) {
|
||||
$this->_data['parent_id'] = absint( $value );
|
||||
if ( $value && ! get_post( $value ) ) {
|
||||
return $this->error( 'Invalid parent ID', $value );
|
||||
}
|
||||
return $this->set_prop( 'parent_id', absint( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order status.
|
||||
* @since 2.7.0
|
||||
* @param string $new_status Status to change the order to. No internal wc- prefix is required.
|
||||
* @param array details of change
|
||||
* @return array details of change
|
||||
*/
|
||||
public function set_status( $new_status ) {
|
||||
$old_status = $this->get_status();
|
||||
|
@ -611,7 +616,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
$new_status = 'pending';
|
||||
}
|
||||
|
||||
$this->_data['status'] = 'wc-' . $new_status;
|
||||
$this->set_prop( 'status', 'wc-' . $new_status );
|
||||
|
||||
// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
|
||||
if ( $old_status && ! in_array( 'wc-' . $old_status, array_keys( wc_get_order_statuses() ) ) ) {
|
||||
|
@ -627,107 +632,121 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
/**
|
||||
* Set order_version
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_version( $value ) {
|
||||
$this->_data['version'] = $value;
|
||||
return $this->set_prop( 'version', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order_currency
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_currency( $value ) {
|
||||
if ( $value && ! in_array( $value, array_keys( get_woocommerce_currencies() ) ) ) {
|
||||
//$this->throw_exception( 'invalid_currency', 'Invalid currency code' );
|
||||
return $this->error( 'Invalid currency code', $value );
|
||||
}
|
||||
$this->_data['currency'] = $value;
|
||||
return $this->set_prop( 'currency', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set prices_include_tax
|
||||
* @param bool $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_prices_include_tax( $value ) {
|
||||
$this->_data['prices_include_tax'] = (bool) $value;
|
||||
return $this->set_prop( 'prices_include_tax', (bool) $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date_created
|
||||
* @param string $timestamp Timestamp
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_date_created( $timestamp ) {
|
||||
$this->_data['date_created'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp );
|
||||
return $this->set_prop( 'date_created', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date_modified
|
||||
* @param string $timestamp
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_date_modified( $timestamp ) {
|
||||
$this->_data['date_modified'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp );
|
||||
return $this->set_prop( 'date_modified', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set discount_total
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_discount_total( $value ) {
|
||||
$this->_data['discount_total'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'discount_total', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set discount_tax
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_discount_tax( $value ) {
|
||||
$this->_data['discount_tax'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'discount_tax', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_total
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_total( $value ) {
|
||||
$this->_data['shipping_total'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'shipping_total', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_tax
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_tax( $value ) {
|
||||
$this->_data['shipping_tax'] = wc_format_decimal( $value );
|
||||
$this->set_prop( 'shipping_tax', wc_format_decimal( $value ) );
|
||||
$this->set_total_tax( $this->get_cart_tax() + $this->get_shipping_tax() );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cart tax
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_cart_tax( $value ) {
|
||||
$this->_data['cart_tax'] = wc_format_decimal( $value );
|
||||
$this->set_prop( 'cart_tax', wc_format_decimal( $value ) );
|
||||
$this->set_total_tax( $this->get_cart_tax() + $this->get_shipping_tax() );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets order tax (sum of cart and shipping tax). Used internaly only.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
protected function set_total_tax( $value ) {
|
||||
$this->_data['total_tax'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'total_tax', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set total
|
||||
* @param string $value
|
||||
* @param string $deprecated Function used to set different totals based on this.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_total( $value, $deprecated = '' ) {
|
||||
if ( $deprecated ) {
|
||||
_deprecated_argument( 'total_type', '2.7', 'Use dedicated total setter methods instead.' );
|
||||
return $this->legacy_set_total( $value, $deprecated );
|
||||
}
|
||||
$this->_data['total'] = wc_format_decimal( $value, wc_get_price_decimals() );
|
||||
return $this->set_prop( 'total', wc_format_decimal( $value, wc_get_price_decimals() ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -110,33 +110,37 @@ class WC_Order_Item_Coupon extends WC_Order_Item {
|
|||
/**
|
||||
* Set order item name.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_name( $value ) {
|
||||
$this->set_code( $value );
|
||||
return $this->set_code( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set code.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_code( $value ) {
|
||||
$this->_data['code'] = wc_clean( $value );
|
||||
return $this->set_prop( 'code', wc_clean( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set discount amount.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_discount( $value ) {
|
||||
$this->_data['discount'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'discount', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set discounted tax amount.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_discount_tax( $value ) {
|
||||
$this->_data['discount_tax'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'discount_tax', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -125,7 +125,7 @@ class WC_Order_Item_Fee extends WC_Order_Item {
|
|||
/**
|
||||
* Set tax class.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_tax_class( $value ) {
|
||||
if ( $value && ! in_array( $value, WC_Tax::get_tax_classes() ) ) {
|
||||
|
@ -137,7 +137,7 @@ class WC_Order_Item_Fee extends WC_Order_Item {
|
|||
/**
|
||||
* Set tax_status.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_tax_status( $value ) {
|
||||
if ( in_array( $value, array( 'taxable', 'none' ) ) ) {
|
||||
|
@ -150,7 +150,7 @@ class WC_Order_Item_Fee extends WC_Order_Item {
|
|||
/**
|
||||
* Set total.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_total( $value ) {
|
||||
return $this->set_prop( 'total', wc_format_decimal( $value ) );
|
||||
|
@ -159,7 +159,7 @@ class WC_Order_Item_Fee extends WC_Order_Item {
|
|||
/**
|
||||
* Set total tax.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_total_tax( $value ) {
|
||||
return $this->set_prop( 'total_tax', wc_format_decimal( $value ) );
|
||||
|
@ -170,7 +170,7 @@ class WC_Order_Item_Fee extends WC_Order_Item {
|
|||
*
|
||||
* This is an array of tax ID keys with total amount values.
|
||||
* @param array $raw_tax_data
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_taxes( $raw_tax_data ) {
|
||||
$raw_tax_data = maybe_unserialize( $raw_tax_data );
|
||||
|
|
|
@ -231,7 +231,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Set quantity.
|
||||
* @param int $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_quantity( $value ) {
|
||||
if ( 0 >= $value ) {
|
||||
|
@ -243,7 +243,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Set tax class.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_tax_class( $value ) {
|
||||
if ( $value && ! in_array( $value, WC_Tax::get_tax_classes() ) ) {
|
||||
|
@ -255,7 +255,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Set Product ID
|
||||
* @param int $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_product_id( $value ) {
|
||||
if ( 0 >= $value || 'product' !== get_post_type( absint( $value ) ) ) {
|
||||
|
@ -267,7 +267,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Set variation ID.
|
||||
* @param int $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_variation_id( $value ) {
|
||||
if ( 0 >= $value || 'product_variation' !== get_post_type( absint( $value ) ) ) {
|
||||
|
@ -279,7 +279,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Line subtotal (before discounts).
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_subtotal( $value ) {
|
||||
return $this->set_prop( 'subtotal', wc_format_decimal( $value ) );
|
||||
|
@ -288,7 +288,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Line total (after discounts).
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_total( $value ) {
|
||||
return $this->set_prop( 'total', wc_format_decimal( $value ) );
|
||||
|
@ -297,7 +297,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Line subtotal tax (before discounts).
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_subtotal_tax( $value ) {
|
||||
return $this->set_prop( 'subtotal_tax', wc_format_decimal( $value ) );
|
||||
|
@ -306,7 +306,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Line total tax (after discounts).
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_total_tax( $value ) {
|
||||
return $this->set_prop( 'total_tax', wc_format_decimal( $value ) );
|
||||
|
@ -315,7 +315,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Set line taxes.
|
||||
* @param array $raw_tax_data
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_taxes( $raw_tax_data ) {
|
||||
$raw_tax_data = maybe_unserialize( $raw_tax_data );
|
||||
|
@ -333,7 +333,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Set variation data (stored as meta data - write only).
|
||||
* @param array $data Key/Value pairs
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_variation( $data ) {
|
||||
foreach ( $data as $key => $value ) {
|
||||
|
@ -345,7 +345,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
|
|||
/**
|
||||
* Set properties based on passed in product object.
|
||||
* @param WC_Product $product
|
||||
* @return bool|WP_Error Returns sucess true or false/WP Error on failure.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_product( $product ) {
|
||||
if ( ! is_a( $product, 'WC_Product' ) ) {
|
||||
|
|
|
@ -114,41 +114,46 @@ class WC_Order_Item_Shipping extends WC_Order_Item {
|
|||
/**
|
||||
* Set order item name.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_name( $value ) {
|
||||
$this->set_method_title( $value );
|
||||
return $this->set_method_title( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set code.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_method_title( $value ) {
|
||||
$this->_data['method_title'] = wc_clean( $value );
|
||||
return $this->set_prop( 'method_title', wc_clean( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping method id.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_method_id( $value ) {
|
||||
$this->_data['method_id'] = wc_clean( $value );
|
||||
return $this->set_prop( 'method_id', wc_clean( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set total.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_total( $value ) {
|
||||
$this->_data['total'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'total', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set total tax.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_total_tax( $value ) {
|
||||
$this->_data['total_tax'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'total_tax', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,6 +161,7 @@ class WC_Order_Item_Shipping extends WC_Order_Item {
|
|||
*
|
||||
* This is an array of tax ID keys with total amount values.
|
||||
* @param array $raw_tax_data
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_taxes( $raw_tax_data ) {
|
||||
$raw_tax_data = maybe_unserialize( $raw_tax_data );
|
||||
|
@ -165,13 +171,15 @@ class WC_Order_Item_Shipping extends WC_Order_Item {
|
|||
if ( ! empty( $raw_tax_data['total'] ) ) {
|
||||
$tax_data['total'] = array_map( 'wc_format_decimal', $raw_tax_data['total'] );
|
||||
}
|
||||
$this->_data['taxes'] = $tax_data;
|
||||
$this->set_prop( 'taxes', $tax_data );
|
||||
$this->set_total_tax( array_sum( $tax_data['total'] ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set properties based on passed in shipping rate object.
|
||||
* @param WC_Shipping_Rate $tax_rate_id
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_rate( $shipping_rate ) {
|
||||
$this->set_method_title( $shipping_rate->label );
|
||||
|
@ -179,6 +187,7 @@ class WC_Order_Item_Shipping extends WC_Order_Item {
|
|||
$this->set_total( $shipping_rate->cost );
|
||||
$this->set_taxes( $shipping_rate->taxes );
|
||||
$this->set_meta_data( $shipping_rate->get_meta_data() );
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -85,68 +85,77 @@ class WC_Order_Item_Tax extends WC_Order_Item {
|
|||
/**
|
||||
* Set order item name.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_name( $value ) {
|
||||
$this->set_rate_code( $value );
|
||||
return $this->set_rate_code( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set item name.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_rate_code( $value ) {
|
||||
$this->_data['rate_code'] = wc_clean( $value );
|
||||
return $this->set_prop( 'rate_code', wc_clean( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set item name.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_label( $value ) {
|
||||
$this->_data['label'] = wc_clean( $value );
|
||||
return $this->set_prop( 'label', wc_clean( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set tax rate id.
|
||||
* @param int $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_rate_id( $value ) {
|
||||
$this->_data['rate_id'] = absint( $value );
|
||||
return $this->set_prop( 'rate_id', absint( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set tax total.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_tax_total( $value ) {
|
||||
$this->_data['tax_total'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'tax_total', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_tax_total
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_tax_total( $value ) {
|
||||
$this->_data['shipping_tax_total'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'shipping_tax_total', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set compound
|
||||
* @param bool $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_compound( $value ) {
|
||||
$this->_data['compound'] = (bool) $value;
|
||||
return $this->set_prop( 'compound', (bool) $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set properties based on passed in tax rate by ID.
|
||||
* @param int $tax_rate_id
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_rate( $tax_rate_id ) {
|
||||
$this->set_rate_id( $tax_rate_id );
|
||||
$this->set_rate_code( WC_Tax::get_rate_code( $tax_rate_id ) );
|
||||
$this->set_label( WC_Tax::get_rate_code( $tax_rate_id ) );
|
||||
$this->set_compound( WC_Tax::get_rate_code( $tax_rate_id ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -152,33 +152,37 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
|
|||
/**
|
||||
* Set ID
|
||||
* @param int $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_id( $value ) {
|
||||
$this->_data['id'] = absint( $value );
|
||||
return $this->set_prop( 'id', absint( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order ID.
|
||||
* @param int $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_order_id( $value ) {
|
||||
$this->_data['order_id'] = absint( $value );
|
||||
return $this->set_prop( 'order_id', absint( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order item name.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_name( $value ) {
|
||||
$this->_data['name'] = wc_clean( $value );
|
||||
return $this->set_prop( 'name', wc_clean( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order item type.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
protected function set_type( $value ) {
|
||||
$this->_data['type'] = wc_clean( $value );
|
||||
return $this->set_prop( 'type', wc_clean( $value ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -115,9 +115,10 @@ class WC_Order_Refund extends WC_Abstract_Order {
|
|||
/**
|
||||
* Set refunded amount.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_amount( $value ) {
|
||||
$this->_data['amount'] = wc_format_decimal( $value );
|
||||
return $this->set_prop( 'amount', wc_format_decimal( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,9 +141,10 @@ class WC_Order_Refund extends WC_Abstract_Order {
|
|||
/**
|
||||
* Set refund reason.
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_reason( $value ) {
|
||||
$this->_data['reason'] = $value;
|
||||
return $this->set_prop( 'reason', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,9 +159,10 @@ class WC_Order_Refund extends WC_Abstract_Order {
|
|||
/**
|
||||
* Set refunded by.
|
||||
* @param int $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_refunded_by( $value ) {
|
||||
$this->_data['refunded_by'] = absint( $value );
|
||||
return $this->set_prop( 'refunded_by', absint( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -815,266 +815,301 @@ class WC_Order extends WC_Abstract_Order {
|
|||
/**
|
||||
* Set order_key.
|
||||
* @param string $value Max length 20 chars.
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_order_key( $value ) {
|
||||
$this->_data['order_key'] = substr( $value, 0, 20 );
|
||||
return $this->set_prop( 'order_key', substr( $value, 0, 20 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set customer_id
|
||||
* @param int $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_customer_id( $value ) {
|
||||
$this->_data['customer_id'] = absint( $value );
|
||||
return $this->set_prop( 'customer_id', absint( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_first_name
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_first_name( $value ) {
|
||||
$this->_data['billing']['first_name'] = $value;
|
||||
return $this->set_prop( array( 'billing' => 'first_name' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_last_name
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_last_name( $value ) {
|
||||
$this->_data['billing']['last_name'] = $value;
|
||||
return $this->set_prop( array( 'billing' => 'last_name' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_company
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_company( $value ) {
|
||||
$this->_data['billing']['company'] = $value;
|
||||
return $this->set_prop( array( 'billing' => 'company' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_address_1
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_address_1( $value ) {
|
||||
$this->_data['billing']['address_1'] = $value;
|
||||
return $this->set_prop( array( 'billing' => 'address_1' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_address_2
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_address_2( $value ) {
|
||||
$this->_data['billing']['address_2'] = $value;
|
||||
return $this->set_prop( array( 'billing' => 'address_2' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_city
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_city( $value ) {
|
||||
$this->_data['billing']['city'] = $value;
|
||||
return $this->set_prop( array( 'billing' => 'city' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_state
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_state( $value ) {
|
||||
$this->_data['billing']['state'] = $value;
|
||||
return $this->set_prop( array( 'billing' => 'state' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_postcode
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_postcode( $value ) {
|
||||
$this->_data['billing']['postcode'] = $value;
|
||||
return $this->set_prop( array( 'billing' => 'postcode' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_country
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_country( $value ) {
|
||||
$this->_data['billing']['country'] = $value;
|
||||
return $this->set_prop( array( 'billing' => 'country' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_email
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_email( $value ) {
|
||||
$value = sanitize_email( $value );
|
||||
$this->_data['billing']['email'] = is_email( $value ) ? $value : '';
|
||||
if ( $value && ! is_email( sanitize_email( $value ) ) ) {
|
||||
return $this->error( 'Invalid email address', $value );
|
||||
}
|
||||
return $this->set_prop( array( 'billing' => 'email' ), sanitize_email( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing_phone
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_billing_phone( $value ) {
|
||||
$this->_data['billing']['phone'] = $value;
|
||||
return $this->set_prop( array( 'billing' => 'phone' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_first_name
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_first_name( $value ) {
|
||||
$this->_data['shipping']['first_name'] = $value;
|
||||
return $this->set_prop( array( 'shipping' => 'first_name' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_last_name
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_last_name( $value ) {
|
||||
$this->_data['shipping']['last_name'] = $value;
|
||||
return $this->set_prop( array( 'shipping' => 'last_name' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_company
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_company( $value ) {
|
||||
$this->_data['shipping']['company'] = $value;
|
||||
return $this->set_prop( array( 'shipping' => 'company' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_address_1
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_address_1( $value ) {
|
||||
$this->_data['shipping']['address_1'] = $value;
|
||||
return $this->set_prop( array( 'shipping' => 'address_1' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_address_2
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_address_2( $value ) {
|
||||
$this->_data['shipping']['address_2'] = $value;
|
||||
return $this->set_prop( array( 'shipping' => 'address_2' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_city
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_city( $value ) {
|
||||
$this->_data['shipping']['city'] = $value;
|
||||
return $this->set_prop( array( 'shipping' => 'city' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_state
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_state( $value ) {
|
||||
$this->_data['shipping']['state'] = $value;
|
||||
return $this->set_prop( array( 'shipping' => 'state' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_postcode
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_postcode( $value ) {
|
||||
$this->_data['shipping']['postcode'] = $value;
|
||||
return $this->set_prop( array( 'shipping' => 'postcode' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shipping_country
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_shipping_country( $value ) {
|
||||
$this->_data['shipping']['country'] = $value;
|
||||
return $this->set_prop( array( 'shipping' => 'country' ), $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the payment method.
|
||||
* @param string $payment_method Supports WC_Payment_Gateway for bw compatibility with < 2.7
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_payment_method( $payment_method = '' ) {
|
||||
if ( is_object( $payment_method ) ) {
|
||||
$this->set_payment_method( $payment_method->id );
|
||||
$this->set_payment_method_title( $payment_method->get_title() );
|
||||
} elseif ( '' === $payment_method ) {
|
||||
$this->_data['payment_method'] = '';
|
||||
$this->_data['payment_method_title'] = '';
|
||||
$this->set_prop( 'payment_method', '' );
|
||||
$this->set_prop( 'payment_method_title', '' );
|
||||
} else {
|
||||
$this->_data['payment_method'] = $payment_method;
|
||||
$this->set_prop( 'payment_method', $payment_method );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set payment_method_title
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_payment_method_title( $value ) {
|
||||
$this->_data['payment_method_title'] = $value;
|
||||
return $this->set_prop( 'payment_method_title', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set transaction_id
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_transaction_id( $value ) {
|
||||
$this->_data['transaction_id'] = $value;
|
||||
return $this->set_prop( 'transaction_id', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set customer_ip_address
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_customer_ip_address( $value ) {
|
||||
$this->_data['customer_ip_address'] = $value;
|
||||
return $this->set_prop( 'customer_ip_address', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set customer_user_agent
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_customer_user_agent( $value ) {
|
||||
$this->_data['customer_user_agent'] = $value;
|
||||
return $this->set_prop( 'customer_user_agent', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set created_via
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_created_via( $value ) {
|
||||
$this->_data['created_via'] = $value;
|
||||
return $this->set_prop( 'created_via', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set customer_note
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_customer_note( $value ) {
|
||||
$this->_data['customer_note'] = $value;
|
||||
return $this->set_prop( 'customer_note', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date_completed
|
||||
* @param string $timestamp
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_date_completed( $timestamp ) {
|
||||
$this->_data['date_completed'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp );
|
||||
return $this->set_prop( 'date_completed', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date_paid
|
||||
* @param string $timestamp
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_date_paid( $timestamp ) {
|
||||
$this->_data['date_paid'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp );
|
||||
return $this->set_prop( 'date_paid', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cart hash
|
||||
* @param string $value
|
||||
* @return bool|WP_Error Returns success true or false/WP Error on failure.
|
||||
*/
|
||||
public function set_cart_hash( $value ) {
|
||||
$this->_data['cart_hash'] = $value;
|
||||
return $this->set_prop( 'cart_hash', $value );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue