diff --git a/includes/abstracts/abstract-wc-legacy-product.php b/includes/abstracts/abstract-wc-legacy-product.php index 2c35bbbbb3a..3399a05320e 100644 --- a/includes/abstracts/abstract-wc-legacy-product.php +++ b/includes/abstracts/abstract-wc-legacy-product.php @@ -84,6 +84,13 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data { case 'post' : $value = get_post( $this->get_id() ); break; + + case 'product_type' : // @todo What do we do with 3rd party use of product_type now it's hardcoded? + $value = $this->get_type(); + break; + + + default : $value = get_post_meta( $this->id, '_' . $key, true ); diff --git a/includes/abstracts/abstract-wc-product.php b/includes/abstracts/abstract-wc-product.php index d09b0354a89..17747c7306d 100644 --- a/includes/abstracts/abstract-wc-product.php +++ b/includes/abstracts/abstract-wc-product.php @@ -32,7 +32,6 @@ class WC_Product extends WC_Abstract_Legacy_Product { 'permalink' => '', 'date_created' => '', 'date_modified' => '', - 'type' => '', 'status' => '', 'featured' => 'no', 'catalog_visibility' => 'hidden', @@ -115,6 +114,24 @@ class WC_Product extends WC_Abstract_Legacy_Product { return apply_filters( 'woocommerce_product_get_name', $this->data['name'], $this ); } + /** + * Get internal type. + * @since 2.7.0 + * @return string + */ + public function get_type() { + return 'simple'; + } + + // @todo below. + + + + + + + + /** * Get product slug. * @@ -154,15 +171,6 @@ class WC_Product extends WC_Abstract_Legacy_Product { return $this->data['date_modified']; } - /** - * Return the product type. - * - * @return string - */ - public function get_type() { - return $this->data['type']; - } - /** * Get product status. * @@ -564,15 +572,6 @@ class WC_Product extends WC_Abstract_Legacy_Product { $this->data['date_modified'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ); } - /** - * Set the product type. - * - * @return string - */ - public function set_type( $type ) { - $this->data['type'] = $type; - } - /** * Set product status. * @@ -1212,7 +1211,7 @@ class WC_Product extends WC_Abstract_Legacy_Product { * @return bool */ public function is_type( $type ) { - return ( $this->product_type == $type || ( is_array( $type ) && in_array( $this->product_type, $type ) ) ) ? true : false; + return ( $this->get_type() === $type || ( is_array( $type ) && in_array( $this->get_type(), $type ) ) ); } /** diff --git a/includes/class-wc-product-external.php b/includes/class-wc-product-external.php index c2ea1351e8b..94a66583d07 100644 --- a/includes/class-wc-product-external.php +++ b/includes/class-wc-product-external.php @@ -18,14 +18,11 @@ if ( ! defined( 'ABSPATH' ) ) { class WC_Product_External extends WC_Product { /** - * Constructor. - * - * @access public - * @param mixed $product + * Get internal type. + * @return string */ - public function __construct( $product ) { - $this->product_type = 'external'; - parent::__construct( $product ); + public function get_type() { + return 'external'; } /** diff --git a/includes/class-wc-product-grouped.php b/includes/class-wc-product-grouped.php index 2814bfe0e41..e5a3b8f4c14 100644 --- a/includes/class-wc-product-grouped.php +++ b/includes/class-wc-product-grouped.php @@ -21,14 +21,11 @@ class WC_Product_Grouped extends WC_Product { public $children; /** - * Constructor. - * - * @access public - * @param mixed $product + * Get internal type. + * @return string */ - public function __construct( $product ) { - $this->product_type = 'grouped'; - parent::__construct( $product ); + public function get_type() { + return 'grouped'; } /** diff --git a/includes/class-wc-product-simple.php b/includes/class-wc-product-simple.php index edb8fe6673a..1852f7aa6c2 100644 --- a/includes/class-wc-product-simple.php +++ b/includes/class-wc-product-simple.php @@ -10,7 +10,6 @@ if ( ! defined( 'ABSPATH' ) ) { * The default product type kinda product. * * @class WC_Product_Simple - * @version 2.0.0 * @package WooCommerce/Classes/Products * @category Class * @author WooThemes @@ -23,11 +22,22 @@ class WC_Product_Simple extends WC_Product { * @param mixed $product */ public function __construct( $product ) { - $this->product_type = 'simple'; $this->supports[] = 'ajax_add_to_cart'; parent::__construct( $product ); } + /** + * Get internal type. + * @return string + */ + public function get_type() { + return 'simple'; + } + + + + + /** * Get the add to url used mainly in loops. * diff --git a/includes/class-wc-product-variable.php b/includes/class-wc-product-variable.php index 80ef48fdd72..9d58aedd266 100644 --- a/includes/class-wc-product-variable.php +++ b/includes/class-wc-product-variable.php @@ -24,13 +24,11 @@ class WC_Product_Variable extends WC_Product { private $prices_array = array(); /** - * Constructor. - * - * @param mixed $product + * Get internal type. + * @return string */ - public function __construct( $product ) { - $this->product_type = 'variable'; - parent::__construct( $product ); + public function get_type() { + return 'variable'; } /** diff --git a/includes/class-wc-product-variation.php b/includes/class-wc-product-variation.php index c9e1152a055..ba9dfd45e93 100644 --- a/includes/class-wc-product-variation.php +++ b/includes/class-wc-product-variation.php @@ -85,7 +85,6 @@ class WC_Product_Variation extends WC_Product { throw new Exception( sprintf( 'No parent product set for variation #%d', $this->variation_id ), 422 ); } - $this->product_type = 'variation'; $this->parent = ! empty( $args['parent'] ) ? $args['parent'] : wc_get_product( $this->id ); $this->post = ! empty( $this->parent->post ) ? $this->parent->post : array(); @@ -95,6 +94,14 @@ class WC_Product_Variation extends WC_Product { } } + /** + * Get internal type. + * @return string + */ + public function get_type() { + return 'variation'; + } + /** * __isset function. *