diff --git a/includes/abstracts/abstract-wc-data.php b/includes/abstracts/abstract-wc-data.php index 1d8b23326f0..6aa8e4a6d9d 100644 --- a/includes/abstracts/abstract-wc-data.php +++ b/includes/abstracts/abstract-wc-data.php @@ -17,30 +17,40 @@ abstract class WC_Data { /** * ID for this object. + * + * @since 2.7.0 * @var int */ protected $id = 0; /** * Core data for this object. Name value pairs (name + default value). + * + * @since 2.7.0 * @var array */ protected $data = array(); /** * Core data changes for this object. + * + * @since 2.7.0 * @var array */ protected $changes = array(); /** * This is false until the object is read from the DB. + * + * @since 2.7.0 * @var bool */ protected $object_read = false; /** * This is the name of this object type. + * + * @since 2.7.0 * @var string */ protected $object_type = 'data'; @@ -49,18 +59,24 @@ abstract class WC_Data { * Extra data for this object. Name value pairs (name + default value). * Used as a standard way for sub classes (like product types) to add * additional information to an inherited class. + * + * @since 2.7.0 * @var array */ protected $extra_data = array(); /** * Set to _data on construct so we can track and reset data if needed. + * + * @since 2.7.0 * @var array */ protected $default_data = array(); /** * Contains a reference to the data store for this class. + * + * @since 2.7.0 * @var object */ protected $data_store; @@ -68,28 +84,36 @@ abstract class WC_Data { /** * Stores meta in cache for future reads. * A group must be set to to enable caching. + * + * @since 2.7.0 * @var string */ protected $cache_group = ''; /** * Stores additonal meta data. + * + * @since 2.7.0 * @var array */ protected $meta_data = null; /** * Default constructor. + * * @param int|object|array $read ID to load from the DB (optional) or already queried data. */ public function __construct( $read = 0 ) { + + $this->data = array_merge( $this->data, $this->extra_data ); + $this->default_data = $this->data; } /** * Get the data store. * - * @since 2.7.0 + * @since 2.7.0 * @return object */ public function get_data_store() { @@ -98,6 +122,8 @@ abstract class WC_Data { /** * Returns the unique ID for this object. + * + * @since 2.6.0 * @return int */ public function get_id() { @@ -107,6 +133,7 @@ abstract class WC_Data { /** * Delete an object, set the ID to 0, and return result. * + * @since 2.6.0 * @param bool $force_delete * @return bool result */ @@ -122,6 +149,7 @@ abstract class WC_Data { /** * Save should create or update based on object existance. * + * @since 2.6.0 * @return int */ public function save() { @@ -140,6 +168,8 @@ abstract class WC_Data { /** * Change data to JSON format. + * + * @since 2.6.0 * @return string Data in JSON format. */ public function __toString() { @@ -148,6 +178,8 @@ abstract class WC_Data { /** * Returns all data for this object. + * + * @since 2.6.0 * @return array */ public function get_data() { @@ -157,7 +189,7 @@ abstract class WC_Data { /** * Returns array of expected data keys for this object. * - * @since 2.7.0 + * @since 2.7.0 * @return array */ public function get_data_keys() { @@ -167,7 +199,7 @@ abstract class WC_Data { /** * Returns all "extra" data keys for an object (for sub objects like product types). * - * @since 2.7.0 + * @since 2.7.0 * @return array */ public function get_extra_data_keys() { @@ -176,6 +208,8 @@ abstract class WC_Data { /** * Filter null meta values from array. + * + * @since 2.7.0 * @return bool */ protected function filter_null_meta( $meta ) { @@ -184,6 +218,7 @@ abstract class WC_Data { /** * Get All Meta Data. + * * @since 2.6.0 * @return array */ @@ -194,6 +229,7 @@ abstract class WC_Data { /** * Get Meta Data by Key. + * * @since 2.6.0 * @param string $key * @param bool $single return first found meta with key, or all with $key @@ -222,6 +258,7 @@ abstract class WC_Data { /** * Set all meta data from array. + * * @since 2.6.0 * @param array $data Key/Value pairs */ @@ -243,6 +280,7 @@ abstract class WC_Data { /** * Add meta data. + * * @since 2.6.0 * @param string $key Meta key * @param string $value Meta value @@ -261,7 +299,8 @@ abstract class WC_Data { /** * Update meta data by key or ID, if provided. - * @since 2.6.0 + * + * @since 2.6.0 * @param string $key * @param string $value * @param int $meta_id @@ -281,6 +320,7 @@ abstract class WC_Data { /** * Delete meta data. + * * @since 2.6.0 * @param array $key Meta key */ @@ -295,6 +335,7 @@ abstract class WC_Data { /** * Delete meta data. + * * @since 2.6.0 * @param int $mid Meta ID */ @@ -371,6 +412,7 @@ abstract class WC_Data { /** * Update Meta Data in the database. + * * @since 2.6.0 */ public function save_meta_data() { @@ -399,6 +441,8 @@ abstract class WC_Data { /** * Set ID. + * + * @since 2.7.0 * @param int $id */ public function set_id( $id ) { @@ -407,6 +451,8 @@ abstract class WC_Data { /** * Set all props to default values. + * + * @since 2.7.0 */ public function set_defaults() { $this->data = $this->default_data; @@ -416,6 +462,8 @@ abstract class WC_Data { /** * Set object read property. + * + * @since 2.7.0 * @param boolean $read */ public function set_object_read( $read = true ) { @@ -424,6 +472,8 @@ abstract class WC_Data { /** * Get object read property. + * + * @since 2.7.0 * @return boolean */ public function get_object_read() { @@ -434,7 +484,8 @@ abstract class WC_Data { * Set a collection of props in one go, collect any errors, and return the result. * Only sets using public methods. * - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. + * @since 2.7.0 + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. * @return WP_Error|bool */ public function set_props( $props, $context = 'set' ) { @@ -541,6 +592,7 @@ abstract class WC_Data { * When invalid data is found, throw an exception unless reading from the DB. * * @throws WC_Data_Exception + * @since 2.7.0 * @param string $code Error code. * @param string $message Error message. * @param int $http_status_code HTTP status code. diff --git a/includes/abstracts/abstract-wc-legacy-order.php b/includes/abstracts/abstract-wc-legacy-order.php index 756f193b4dd..7e6483e25e4 100644 --- a/includes/abstracts/abstract-wc-legacy-order.php +++ b/includes/abstracts/abstract-wc-legacy-order.php @@ -402,13 +402,13 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data { wc_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '2.7' ); if ( 'completed_date' === $key ) { - return $this->get_date_completed(); + return date( 'Y-m-d H:i:s', $this->get_date_completed() ); } elseif ( 'paid_date' === $key ) { return $this->get_date_paid(); } elseif ( 'modified_date' === $key ) { - return $this->get_date_modified(); + return date( 'Y-m-d H:i:s', $this->get_date_modified() ); } elseif ( 'order_date' === $key ) { - return $this->get_date_created(); + return date( 'Y-m-d H:i:s', $this->get_date_created() ); } elseif ( 'id' === $key ) { return $this->get_id(); } elseif ( 'post' === $key ) { diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-data.php b/includes/admin/meta-boxes/class-wc-meta-box-order-data.php index f4246af4025..6e5a89b9cef 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-data.php @@ -263,7 +263,7 @@ class WC_Meta_Box_Order_Data { } ?>

diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index ca6cc854b8f..0a4955503ef 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -429,7 +429,7 @@ class WC_AJAX { } wp_safe_redirect( wp_get_referer() ? remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids' ), wp_get_referer() ) : admin_url( 'edit.php?post_type=product' ) ); - wp_die(); + exit; } /** @@ -447,7 +447,7 @@ class WC_AJAX { } wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'edit.php?post_type=shop_order' ) ); - wp_die(); + exit; } /** diff --git a/includes/class-wc-order-item.php b/includes/class-wc-order-item.php index 51bb8b77a3a..6631b002bd8 100644 --- a/includes/class-wc-order-item.php +++ b/includes/class-wc-order-item.php @@ -57,7 +57,6 @@ class WC_Order_Item extends WC_Data implements ArrayAccess { * @param int|object|array $item ID to load from the DB, or WC_Order_Item Object */ public function __construct( $item = 0 ) { - $this->data = array_merge( $this->data, $this->extra_data ); parent::__construct( $item ); if ( $item instanceof WC_Order_Item ) { diff --git a/includes/class-wc-order-refund.php b/includes/class-wc-order-refund.php index 7ac150d7a89..db9e9823d9b 100644 --- a/includes/class-wc-order-refund.php +++ b/includes/class-wc-order-refund.php @@ -38,16 +38,6 @@ class WC_Order_Refund extends WC_Abstract_Order { 'refunded_by' => 0, ); - /** - * Extend the abstract _data properties and then read the order object. - * - * @param int|object|WC_Order $read Order to init. - */ - public function __construct( $read = 0 ) { - $this->data = array_merge( $this->data, $this->extra_data ); - parent::__construct( $read ); - } - /** * Get internal type (post type.) * @return string diff --git a/includes/class-wc-product-external.php b/includes/class-wc-product-external.php index 7ef27817ee9..1d81376a193 100644 --- a/includes/class-wc-product-external.php +++ b/includes/class-wc-product-external.php @@ -26,15 +26,6 @@ class WC_Product_External extends WC_Product { 'button_text' => '', ); - /** - * Merges external product data into the parent object. - * @param int|WC_Product|object $product Product to init. - */ - public function __construct( $product = 0 ) { - $this->data = array_merge( $this->data, $this->extra_data ); - parent::__construct( $product ); - } - /** * Get internal type. * @return string diff --git a/includes/class-wc-product-grouped.php b/includes/class-wc-product-grouped.php index 87bac32435f..d67279b65e8 100644 --- a/includes/class-wc-product-grouped.php +++ b/includes/class-wc-product-grouped.php @@ -25,15 +25,6 @@ class WC_Product_Grouped extends WC_Product { 'children' => array(), ); - /** - * Merges grouped product data into the parent object. - * @param int|WC_Product|object $product Product to init. - */ - public function __construct( $product = 0 ) { - $this->data = array_merge( $this->data, $this->extra_data ); - parent::__construct( $product ); - } - /** * Get internal type. * @return string diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index de80a500b6a..c242de60d21 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -238,7 +238,7 @@ class WC_Shipping { * @param array $packages multi-dimensional array of cart items to calc shipping for */ public function calculate_shipping( $packages = array() ) { - $this->shipping_total = null; + $this->shipping_total = 0; $this->shipping_taxes = array(); $this->packages = array(); @@ -393,7 +393,7 @@ class WC_Shipping { */ public function reset_shipping() { unset( WC()->session->chosen_shipping_methods ); - $this->shipping_total = null; + $this->shipping_total = 0; $this->shipping_taxes = array(); $this->packages = array(); } diff --git a/includes/class-wc-tax.php b/includes/class-wc-tax.php index 23576e0c69c..73d956a3058 100644 --- a/includes/class-wc-tax.php +++ b/includes/class-wc-tax.php @@ -410,8 +410,8 @@ class WC_Tax { LEFT OUTER JOIN {$wpdb->prefix}woocommerce_tax_rate_locations as locations ON tax_rates.tax_rate_id = locations.tax_rate_id LEFT OUTER JOIN {$wpdb->prefix}woocommerce_tax_rate_locations as locations2 ON tax_rates.tax_rate_id = locations2.tax_rate_id WHERE 1=1 AND " . implode( ' AND ', $criteria ) . " - GROUP BY tax_rate_id - ORDER BY tax_rate_priority + GROUP BY tax_rates.tax_rate_id + ORDER BY tax_rates.tax_rate_priority " ); $found_rates = self::sort_rates( $found_rates ); diff --git a/includes/data-stores/class-wc-product-variable-data-store-cpt.php b/includes/data-stores/class-wc-product-variable-data-store-cpt.php index 1c2d4e6d1b9..2962b9f771f 100644 --- a/includes/data-stores/class-wc-product-variable-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-variable-data-store-cpt.php @@ -267,7 +267,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple */ public function child_has_weight( $product ) { global $wpdb; - $children = $product->get_visible_children( 'edit' ); + $children = $product->get_visible_children(); return $children ? $wpdb->get_var( "SELECT 1 FROM $wpdb->postmeta WHERE meta_key = '_weight' AND meta_value > 0 AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) : false; } @@ -280,7 +280,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple */ public function child_has_dimensions( $product ) { global $wpdb; - $children = $product->get_visible_children( 'edit' ); + $children = $product->get_visible_children(); return $children ? $wpdb->get_var( "SELECT 1 FROM $wpdb->postmeta WHERE meta_key IN ( '_length', '_width', '_height' ) AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) : false; } @@ -293,7 +293,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple */ public function child_is_in_stock( $product ) { global $wpdb; - $children = $product->get_visible_children( 'edit' ); + $children = $product->get_visible_children(); $oufofstock_children = $children ? $wpdb->get_var( "SELECT COUNT( post_id ) FROM $wpdb->postmeta WHERE meta_key = '_stock_status' AND meta_value = 'instock' AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) : 0; return $children > $oufofstock_children; } @@ -361,7 +361,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple public function sync_price( &$product ) { global $wpdb; - $children = $product->get_visible_children( 'edit' ); + $children = $product->get_visible_children(); $prices = $children ? array_unique( $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_price' AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) ) : array(); delete_post_meta( $product->get_id(), '_price' ); diff --git a/includes/wc-cart-functions.php b/includes/wc-cart-functions.php index ba159bfb1fe..3bd5fae9141 100644 --- a/includes/wc-cart-functions.php +++ b/includes/wc-cart-functions.php @@ -82,7 +82,6 @@ function wc_get_raw_referer() { /** * Add to cart messages. * - * @access public * @param int|array $products * @param bool $show_qty Should qty's be shown? Added in 2.6.0 * @param bool $return Return message rather than add it. @@ -116,7 +115,12 @@ function wc_add_to_cart_message( $products, $show_qty = false, $return = false ) $message = sprintf( '%s %s', esc_url( wc_get_page_permalink( 'cart' ) ), esc_html__( 'View cart', 'woocommerce' ), esc_html( $added_text ) ); } - $message = apply_filters( 'wc_add_to_cart_message', $message, $product_id ); + if ( has_filter( 'wc_add_to_cart_message' ) ) { + wc_deprecated_function( 'The wc_add_to_cart_message filter', '2.7', 'wc_add_to_cart_message_html' ); + $message = apply_filters( 'wc_add_to_cart_message', $message, $product_id ); + } + + $message = apply_filters( 'wc_add_to_cart_message_html', $message, $products ); if ( $return ) { return $message;