diff --git a/includes/abstracts/abstract-wc-data.php b/includes/abstracts/abstract-wc-data.php index c6e3ac21855..1b0627171c3 100644 --- a/includes/abstracts/abstract-wc-data.php +++ b/includes/abstracts/abstract-wc-data.php @@ -380,36 +380,31 @@ abstract class WC_Data { /** * Set internal data prop to specified value. * @param int ...$param Prop keys followed by value to set. - * @return bool + * @throws WC_Data_Exception */ protected function set_prop() { - $args = func_get_args(); - - if ( sizeof( $args ) < 2 ) { - return false; + if ( func_num_args() < 2 ) { + $this->throw_exception( 'invalid_value', 'set_prop requires at least 2 parameters' ); } - $value = array_pop( $args ); - $target = &$this->_data; + $args = func_get_args(); + $value = array_pop( $args ); + $prop = &$this->_data; foreach ( $args as $arg ) { - if ( ! isset( $target[ $arg ] ) ) { - return false; - } - $target = &$target[ $arg ]; + $prop = &$prop[ $arg ]; } - $target = $value; - return true; + $prop = $value; } /** * Returns an invalid data WP_Error object. * @param string $message Error Message. * @param mixed $data Data the user tried to set. - * @return WP_Error + * @throws WC_Data_Exception */ - protected function error( $message = '', $data = '' ) { - return new WP_Error( 'invalid-data', $message, $data ); + protected function throw_exception( $error_code, $error_message, $http_status_code = 400 ) { + throw new WC_Data_Exception( $error_code, $error_message, $http_status_code ); } } diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index cb0a87dcba1..84c8eea8768 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -583,23 +583,23 @@ 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. + * @throws WC_Data_Exception */ public function set_id( $value ) { - return $this->set_prop( 'id', absint( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_parent_id( $value ) { if ( $value && ! get_post( $value ) ) { - return $this->error( 'Invalid parent ID', $value ); + $this->throw_exception( 'order_invalid_parent_id', __( 'Invalid parent ID', 'woocommerce' ) ); } - return $this->set_prop( 'parent_id', absint( $value ) ); + $this->set_prop( 'parent_id', absint( $value ) ); } /** @@ -633,121 +633,119 @@ 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. + * @throws WC_Data_Exception */ public function set_version( $value ) { - return $this->set_prop( 'version', $value ); + $this->set_prop( 'version', $value ); } /** * Set order_currency * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_currency( $value ) { if ( $value && ! in_array( $value, array_keys( get_woocommerce_currencies() ) ) ) { - return $this->error( 'Invalid currency code', $value ); + $this->throw_exception( 'order_invalid_currency', __( 'Invalid currency code', 'woocommerce' ) ); } - return $this->set_prop( 'currency', $value ); + $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. + * @throws WC_Data_Exception */ public function set_prices_include_tax( $value ) { - return $this->set_prop( 'prices_include_tax', (bool) $value ); + $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. + * @throws WC_Data_Exception */ public function set_date_created( $timestamp ) { - return $this->set_prop( 'date_created', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) ); + $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. + * @throws WC_Data_Exception */ public function set_date_modified( $timestamp ) { - return $this->set_prop( 'date_modified', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) ); + $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. + * @throws WC_Data_Exception */ public function set_discount_total( $value ) { - return $this->set_prop( 'discount_total', wc_format_decimal( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_discount_tax( $value ) { - return $this->set_prop( 'discount_tax', wc_format_decimal( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_shipping_total( $value ) { - return $this->set_prop( 'shipping_total', wc_format_decimal( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_shipping_tax( $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. + * @throws WC_Data_Exception */ public function set_cart_tax( $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. + * @throws WC_Data_Exception */ protected function set_total_tax( $value ) { - return $this->set_prop( 'total_tax', wc_format_decimal( $value ) ); + $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. + * @throws WC_Data_Exception */ 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 ); } - return $this->set_prop( 'total', wc_format_decimal( $value, wc_get_price_decimals() ) ); + $this->set_prop( 'total', wc_format_decimal( $value, wc_get_price_decimals() ) ); } /* diff --git a/includes/class-wc-order-item-coupon.php b/includes/class-wc-order-item-coupon.php index b8f029ea5b5..9b800c6f915 100644 --- a/includes/class-wc-order-item-coupon.php +++ b/includes/class-wc-order-item-coupon.php @@ -110,7 +110,7 @@ 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. + * @throws WC_Data_Exception */ public function set_name( $value ) { return $this->set_code( $value ); @@ -119,28 +119,28 @@ class WC_Order_Item_Coupon extends WC_Order_Item { /** * Set code. * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_code( $value ) { - return $this->set_prop( 'code', wc_clean( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_discount( $value ) { - return $this->set_prop( 'discount', wc_format_decimal( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_discount_tax( $value ) { - return $this->set_prop( 'discount_tax', wc_format_decimal( $value ) ); + $this->set_prop( 'discount_tax', wc_format_decimal( $value ) ); } /* diff --git a/includes/class-wc-order-item-fee.php b/includes/class-wc-order-item-fee.php index 408ca05dca1..3cf657c90c7 100644 --- a/includes/class-wc-order-item-fee.php +++ b/includes/class-wc-order-item-fee.php @@ -125,44 +125,44 @@ class WC_Order_Item_Fee extends WC_Order_Item { /** * Set tax class. * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_tax_class( $value ) { if ( $value && ! in_array( $value, WC_Tax::get_tax_classes() ) ) { - return $this->error( 'Invalid tax class', $value ); + $this->throw_exception( 'order_item_fee_invalid_tax_class', __( 'Invalid tax class', 'woocommerce' ) ); } - return $this->set_prop( 'tax_class', $value ); + $this->set_prop( 'tax_class', $value ); } /** * Set tax_status. * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_tax_status( $value ) { if ( in_array( $value, array( 'taxable', 'none' ) ) ) { - return $this->set_prop( 'tax_status', $value ); + $this->set_prop( 'tax_status', $value ); } else { - return $this->set_prop( 'tax_status', 'taxable' ); + $this->set_prop( 'tax_status', 'taxable' ); } } /** * Set total. * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_total( $value ) { - return $this->set_prop( 'total', wc_format_decimal( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_total_tax( $value ) { - return $this->set_prop( 'total_tax', wc_format_decimal( $value ) ); + $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 success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_taxes( $raw_tax_data ) { $raw_tax_data = maybe_unserialize( $raw_tax_data ); @@ -180,7 +180,7 @@ class WC_Order_Item_Fee extends WC_Order_Item { if ( ! empty( $raw_tax_data['total'] ) ) { $tax_data['total'] = array_map( 'wc_format_decimal', $raw_tax_data['total'] ); } - return $this->set_prop( 'taxes', $tax_data ); + $this->set_prop( 'taxes', $tax_data ); } /* diff --git a/includes/class-wc-order-item-product.php b/includes/class-wc-order-item-product.php index eeffc4f33ce..77250347fec 100644 --- a/includes/class-wc-order-item-product.php +++ b/includes/class-wc-order-item-product.php @@ -231,91 +231,91 @@ class WC_Order_Item_Product extends WC_Order_Item { /** * Set quantity. * @param int $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_quantity( $value ) { if ( 0 >= $value ) { - return $this->error( 'Quantity must be positive', $value ); + $this->throw_exception( 'order_item_product_invalid_quantity', __( 'Quantity must be positive', 'woocommerce' ) ); } - return $this->set_prop( 'quantity', wc_stock_amount( $value ) ); + $this->set_prop( 'quantity', wc_stock_amount( $value ) ); } /** * Set tax class. * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_tax_class( $value ) { if ( $value && ! in_array( $value, WC_Tax::get_tax_classes() ) ) { - return $this->error( 'Invalid tax class', $value ); + $this->throw_exception( 'order_item_product_invalid_tax_class', __( 'Invalid tax class', 'woocommerce' ) ); } - return $this->set_prop( 'tax_class', $value ); + $this->set_prop( 'tax_class', $value ); } /** * Set Product ID * @param int $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_product_id( $value ) { if ( 0 >= $value || 'product' !== get_post_type( absint( $value ) ) ) { - return $this->error( 'Invalid product ID', $value ); + $this->throw_exception( 'order_item_product_invalid_product_id', __( 'Invalid product ID', 'woocommerce' ) ); } - return $this->set_prop( 'product_id', absint( $value ) ); + $this->set_prop( 'product_id', absint( $value ) ); } /** * Set variation ID. * @param int $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_variation_id( $value ) { if ( 0 >= $value || 'product_variation' !== get_post_type( absint( $value ) ) ) { - return $this->error( 'Invalid product ID', $value ); + $this->throw_exception( 'order_item_product_invalid_variation_id', __( 'Invalid variation ID', 'woocommerce' ) ); } - return $this->set_prop( 'variation_id', absint( $value ) ); + $this->set_prop( 'variation_id', absint( $value ) ); } /** * Line subtotal (before discounts). * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_subtotal( $value ) { - return $this->set_prop( 'subtotal', wc_format_decimal( $value ) ); + $this->set_prop( 'subtotal', wc_format_decimal( $value ) ); } /** * Line total (after discounts). * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_total( $value ) { - return $this->set_prop( 'total', wc_format_decimal( $value ) ); + $this->set_prop( 'total', wc_format_decimal( $value ) ); } /** * Line subtotal tax (before discounts). * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_subtotal_tax( $value ) { - return $this->set_prop( 'subtotal_tax', wc_format_decimal( $value ) ); + $this->set_prop( 'subtotal_tax', wc_format_decimal( $value ) ); } /** * Line total tax (after discounts). * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_total_tax( $value ) { - return $this->set_prop( 'total_tax', wc_format_decimal( $value ) ); + $this->set_prop( 'total_tax', wc_format_decimal( $value ) ); } /** * Set line taxes. * @param array $raw_tax_data - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_taxes( $raw_tax_data ) { $raw_tax_data = maybe_unserialize( $raw_tax_data ); @@ -327,13 +327,13 @@ class WC_Order_Item_Product extends WC_Order_Item { $tax_data['total'] = array_map( 'wc_format_decimal', $raw_tax_data['total'] ); $tax_data['subtotal'] = array_map( 'wc_format_decimal', $raw_tax_data['subtotal'] ); } - return $this->set_prop( 'taxes', $tax_data ); + $this->set_prop( 'taxes', $tax_data ); } /** * Set variation data (stored as meta data - write only). * @param array $data Key/Value pairs - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_variation( $data ) { foreach ( $data as $key => $value ) { @@ -345,11 +345,11 @@ 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 success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_product( $product ) { if ( ! is_a( $product, 'WC_Product' ) ) { - return $this->error( 'Invalid product', $product ); + $this->throw_exception( 'order_item_product_invalid_product', __( 'Invalid product', 'woocommerce' ) ); } $this->set_product_id( $product->get_id() ); $this->set_name( $product->get_title() ); diff --git a/includes/class-wc-order-item-shipping.php b/includes/class-wc-order-item-shipping.php index 816404a8193..e2aa57cc9b6 100644 --- a/includes/class-wc-order-item-shipping.php +++ b/includes/class-wc-order-item-shipping.php @@ -114,7 +114,7 @@ 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. + * @throws WC_Data_Exception */ public function set_name( $value ) { return $this->set_method_title( $value ); @@ -123,37 +123,37 @@ class WC_Order_Item_Shipping extends WC_Order_Item { /** * Set code. * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_method_title( $value ) { - return $this->set_prop( 'method_title', wc_clean( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_method_id( $value ) { - return $this->set_prop( 'method_id', wc_clean( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_total( $value ) { - return $this->set_prop( 'total', wc_format_decimal( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_total_tax( $value ) { - return $this->set_prop( 'total_tax', wc_format_decimal( $value ) ); + $this->set_prop( 'total_tax', wc_format_decimal( $value ) ); } /** @@ -161,7 +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. + * @throws WC_Data_Exception */ public function set_taxes( $raw_tax_data ) { $raw_tax_data = maybe_unserialize( $raw_tax_data ); @@ -173,13 +173,12 @@ class WC_Order_Item_Shipping extends WC_Order_Item { } $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. + * @throws WC_Data_Exception */ public function set_shipping_rate( $shipping_rate ) { $this->set_method_title( $shipping_rate->label ); @@ -187,7 +186,6 @@ 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; } /* diff --git a/includes/class-wc-order-item-tax.php b/includes/class-wc-order-item-tax.php index 2d5526fcafd..c88d3bf3bba 100644 --- a/includes/class-wc-order-item-tax.php +++ b/includes/class-wc-order-item-tax.php @@ -85,7 +85,7 @@ 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. + * @throws WC_Data_Exception */ public function set_name( $value ) { return $this->set_rate_code( $value ); @@ -94,68 +94,67 @@ class WC_Order_Item_Tax extends WC_Order_Item { /** * Set item name. * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_rate_code( $value ) { - return $this->set_prop( 'rate_code', wc_clean( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_label( $value ) { - return $this->set_prop( 'label', wc_clean( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_rate_id( $value ) { - return $this->set_prop( 'rate_id', absint( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_tax_total( $value ) { - return $this->set_prop( 'tax_total', wc_format_decimal( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_shipping_tax_total( $value ) { - return $this->set_prop( 'shipping_tax_total', wc_format_decimal( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_compound( $value ) { - return $this->set_prop( 'compound', (bool) $value ); + $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. + * @throws WC_Data_Exception */ 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; } /* diff --git a/includes/class-wc-order-item.php b/includes/class-wc-order-item.php index 5b1e7731c77..0b84b63c73a 100644 --- a/includes/class-wc-order-item.php +++ b/includes/class-wc-order-item.php @@ -152,37 +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. + * @throws WC_Data_Exception */ public function set_id( $value ) { - return $this->set_prop( 'id', absint( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_order_id( $value ) { - return $this->set_prop( 'order_id', absint( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_name( $value ) { - return $this->set_prop( 'name', wc_clean( $value ) ); + $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. + * @throws WC_Data_Exception */ protected function set_type( $value ) { - return $this->set_prop( 'type', wc_clean( $value ) ); + $this->set_prop( 'type', wc_clean( $value ) ); } /* diff --git a/includes/class-wc-order-refund.php b/includes/class-wc-order-refund.php index 4e79dded5ef..dfb28d5455c 100644 --- a/includes/class-wc-order-refund.php +++ b/includes/class-wc-order-refund.php @@ -115,10 +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. + * @throws WC_Data_Exception */ public function set_amount( $value ) { - return $this->set_prop( 'amount', wc_format_decimal( $value ) ); + $this->set_prop( 'amount', wc_format_decimal( $value ) ); } /** @@ -141,10 +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. + * @throws WC_Data_Exception */ public function set_reason( $value ) { - return $this->set_prop( 'reason', $value ); + $this->set_prop( 'reason', $value ); } /** @@ -159,10 +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. + * @throws WC_Data_Exception */ public function set_refunded_by( $value ) { - return $this->set_prop( 'refunded_by', absint( $value ) ); + $this->set_prop( 'refunded_by', absint( $value ) ); } /** diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php index ecc5b2d9000..1e92e43def2 100644 --- a/includes/class-wc-order.php +++ b/includes/class-wc-order.php @@ -815,208 +815,208 @@ 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. + * @throws WC_Data_Exception */ public function set_order_key( $value ) { - return $this->set_prop( 'order_key', substr( $value, 0, 20 ) ); + $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. + * @throws WC_Data_Exception */ public function set_customer_id( $value ) { - return $this->set_prop( 'customer_id', absint( $value ) ); + $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. + * @throws WC_Data_Exception */ public function set_billing_first_name( $value ) { - return $this->set_prop( 'billing', 'first_name', $value ); + $this->set_prop( 'billing', 'first_name', $value ); } /** * Set billing_last_name * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_billing_last_name( $value ) { - return $this->set_prop( 'billing', 'last_name', $value ); + $this->set_prop( 'billing', 'last_name', $value ); } /** * Set billing_company * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_billing_company( $value ) { - return $this->set_prop( 'billing', 'company', $value ); + $this->set_prop( 'billing', 'company', $value ); } /** * Set billing_address_1 * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_billing_address_1( $value ) { - return $this->set_prop( 'billing', 'address_1', $value ); + $this->set_prop( 'billing', 'address_1', $value ); } /** * Set billing_address_2 * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_billing_address_2( $value ) { - return $this->set_prop( 'billing', 'address_2', $value ); + $this->set_prop( 'billing', 'address_2', $value ); } /** * Set billing_city * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_billing_city( $value ) { - return $this->set_prop( 'billing', 'city', $value ); + $this->set_prop( 'billing', 'city', $value ); } /** * Set billing_state * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_billing_state( $value ) { - return $this->set_prop( 'billing', 'state', $value ); + $this->set_prop( 'billing', 'state', $value ); } /** * Set billing_postcode * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_billing_postcode( $value ) { - return $this->set_prop( 'billing', 'postcode', $value ); + $this->set_prop( 'billing', 'postcode', $value ); } /** * Set billing_country * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_billing_country( $value ) { - return $this->set_prop( 'billing', 'country', $value ); + $this->set_prop( 'billing', 'country', $value ); } /** * Set billing_email * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_billing_email( $value ) { if ( $value && ! is_email( $value ) ) { - return $this->error( 'Invalid email address', $value ); + $this->throw_exception( 'order_invalid_billing_email', __( 'Invalid order billing email address', 'woocommerce' ) ); } - return $this->set_prop( 'billing', 'email', sanitize_email( $value ) ); + $this->set_prop( 'billing', 'email', sanitize_email( $value ) ); } /** * Set billing_phone * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_billing_phone( $value ) { - return $this->set_prop( 'billing', 'phone', $value ); + $this->set_prop( 'billing', 'phone', $value ); } /** * Set shipping_first_name * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_shipping_first_name( $value ) { - return $this->set_prop( 'shipping', 'first_name', $value ); + $this->set_prop( 'shipping', 'first_name', $value ); } /** * Set shipping_last_name * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_shipping_last_name( $value ) { - return $this->set_prop( 'shipping', 'last_name', $value ); + $this->set_prop( 'shipping', 'last_name', $value ); } /** * Set shipping_company * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_shipping_company( $value ) { - return $this->set_prop( 'shipping', 'company', $value ); + $this->set_prop( 'shipping', 'company', $value ); } /** * Set shipping_address_1 * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_shipping_address_1( $value ) { - return $this->set_prop( 'shipping', 'address_1', $value ); + $this->set_prop( 'shipping', 'address_1', $value ); } /** * Set shipping_address_2 * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_shipping_address_2( $value ) { - return $this->set_prop( 'shipping', 'address_2', $value ); + $this->set_prop( 'shipping', 'address_2', $value ); } /** * Set shipping_city * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_shipping_city( $value ) { - return $this->set_prop( 'shipping', 'city', $value ); + $this->set_prop( 'shipping', 'city', $value ); } /** * Set shipping_state * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_shipping_state( $value ) { - return $this->set_prop( 'shipping', 'state', $value ); + $this->set_prop( 'shipping', 'state', $value ); } /** * Set shipping_postcode * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_shipping_postcode( $value ) { - return $this->set_prop( 'shipping', 'postcode', $value ); + $this->set_prop( 'shipping', 'postcode', $value ); } /** * Set shipping_country * @param string $value - * @return bool|WP_Error Returns success true or false/WP Error on failure. + * @throws WC_Data_Exception */ public function set_shipping_country( $value ) { - return $this->set_prop( 'shipping', 'country', $value ); + $this->set_prop( '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. + * @throws WC_Data_Exception */ public function set_payment_method( $payment_method = '' ) { if ( is_object( $payment_method ) ) { @@ -1028,88 +1028,87 @@ class WC_Order extends WC_Abstract_Order { } else { $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. + * @throws WC_Data_Exception */ public function set_payment_method_title( $value ) { - return $this->set_prop( 'payment_method_title', $value ); + $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. + * @throws WC_Data_Exception */ public function set_transaction_id( $value ) { - return $this->set_prop( 'transaction_id', $value ); + $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. + * @throws WC_Data_Exception */ public function set_customer_ip_address( $value ) { - return $this->set_prop( 'customer_ip_address', $value ); + $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. + * @throws WC_Data_Exception */ public function set_customer_user_agent( $value ) { - return $this->set_prop( 'customer_user_agent', $value ); + $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. + * @throws WC_Data_Exception */ public function set_created_via( $value ) { - return $this->set_prop( 'created_via', $value ); + $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. + * @throws WC_Data_Exception */ public function set_customer_note( $value ) { - return $this->set_prop( 'customer_note', $value ); + $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. + * @throws WC_Data_Exception */ public function set_date_completed( $timestamp ) { - return $this->set_prop( 'date_completed', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) ); + $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. + * @throws WC_Data_Exception */ public function set_date_paid( $timestamp ) { - return $this->set_prop( 'date_paid', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) ); + $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. + * @throws WC_Data_Exception */ public function set_cart_hash( $value ) { - return $this->set_prop( 'cart_hash', $value ); + $this->set_prop( 'cart_hash', $value ); } /*