Changed wc_get_product_classname function name to wc_get_product_object
This commit is contained in:
parent
ba0773d12e
commit
8033d5751e
|
@ -453,7 +453,7 @@ class WC_Meta_Box_Product_Data {
|
|||
continue;
|
||||
}
|
||||
$variation_id = absint( $_POST['variable_post_id'][ $i ] );
|
||||
$variation = wc_get_product_classname( 'variation', $variation_id );
|
||||
$variation = wc_get_product_object( 'variation', $variation_id );
|
||||
$stock = null;
|
||||
|
||||
// Handle stock changes.
|
||||
|
|
|
@ -707,8 +707,8 @@ class WC_AJAX {
|
|||
$product_id = intval( $_POST['post_id'] );
|
||||
$post = get_post( $product_id ); // phpcs:ignore
|
||||
$loop = intval( $_POST['loop'] );
|
||||
$product_object = wc_get_product_classname( 'variable', $product_id ); // Forces type to variable in case product is unsaved.
|
||||
$variation_object = wc_get_product_classname( 'variation' );
|
||||
$product_object = wc_get_product_object( 'variable', $product_id ); // Forces type to variable in case product is unsaved.
|
||||
$variation_object = wc_get_product_object( 'variation' );
|
||||
$variation_object->set_parent_id( $product_id );
|
||||
$variation_object->set_attributes( array_fill_keys( array_map( 'sanitize_title', array_keys( $product_object->get_variation_attributes() ) ), '' ) );
|
||||
$variation_id = $variation_object->save();
|
||||
|
|
|
@ -512,7 +512,7 @@ class WC_Shortcodes {
|
|||
// Check if sku is a variation.
|
||||
if ( isset( $atts['sku'] ) && $single_product->have_posts() && 'product_variation' === $single_product->post->post_type ) {
|
||||
|
||||
$variation = wc_get_product_classname( 'variation', $single_product->post->ID );
|
||||
$variation = wc_get_product_object( 'variation', $single_product->post->ID );
|
||||
$attributes = $variation->get_attributes();
|
||||
|
||||
// Set preselected id to be used by JS to provide context.
|
||||
|
|
|
@ -1178,7 +1178,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
if ( in_array( $possible_attribute, $existing_attributes ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
|
||||
continue;
|
||||
}
|
||||
$variation = wc_get_product_classname( 'variation' );
|
||||
$variation = wc_get_product_object( 'variation' );
|
||||
$variation->set_parent_id( $product->get_id() );
|
||||
$variation->set_attributes( $possible_attribute );
|
||||
$variation_id = $variation->save();
|
||||
|
|
|
@ -173,7 +173,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
|
|||
return new WP_Error( 'woocommerce_product_importer_invalid_type', __( 'Invalid product type.', 'woocommerce' ), array( 'status' => 401 ) );
|
||||
}
|
||||
|
||||
$product = wc_get_product_classname( $data['type'], $id );
|
||||
$product = wc_get_product_object( $data['type'], $id );
|
||||
} elseif ( ! empty( $data['id'] ) ) {
|
||||
$product = wc_get_product( $id );
|
||||
|
||||
|
@ -189,7 +189,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
$product = wc_get_product_classname( 'simple', $id );
|
||||
$product = wc_get_product_object( 'simple', $id );
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_product_import_get_product_object', $product, $data );
|
||||
|
|
|
@ -183,7 +183,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
|
|||
|
||||
// If we're not updating existing posts, we may need a placeholder product to map to.
|
||||
if ( ! $this->params['update_existing'] ) {
|
||||
$product = wc_get_product_classname( 'simple' );
|
||||
$product = wc_get_product_object( 'simple' );
|
||||
$product->set_name( 'Import placeholder for ' . $id );
|
||||
$product->set_status( 'importing' );
|
||||
$product->add_meta_data( '_original_id', $id, true );
|
||||
|
@ -200,7 +200,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
|
|||
}
|
||||
|
||||
try {
|
||||
$product = wc_get_product_classname( 'simple' );
|
||||
$product = wc_get_product_object( 'simple' );
|
||||
$product->set_name( 'Import placeholder for ' . $value );
|
||||
$product->set_status( 'importing' );
|
||||
$product->set_sku( $value );
|
||||
|
@ -254,7 +254,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
|
|||
return $id_from_sku;
|
||||
}
|
||||
|
||||
$product = wc_get_product_classname( 'simple' );
|
||||
$product = wc_get_product_object( 'simple' );
|
||||
$product->set_name( 'Import placeholder for ' . $id );
|
||||
$product->set_status( 'importing' );
|
||||
$product->add_meta_data( '_original_id', $id, true );
|
||||
|
|
|
@ -65,15 +65,15 @@ function wc_get_product( $the_product = false, $deprecated = array() ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get product class name.
|
||||
* Get a product object.
|
||||
*
|
||||
* @see WC_Product_Factory::get_product_classname
|
||||
* @since 3.9.0
|
||||
* @param string $product_type Product type.
|
||||
* @param string $product_type Product type. If used an invalid type a WC_Product_Simple instance will be returned.
|
||||
* @param int $product_id Product ID.
|
||||
* @return WC_Product
|
||||
*/
|
||||
function wc_get_product_classname( $product_type, $product_id = 0 ) {
|
||||
function wc_get_product_object( $product_type, $product_id = 0 ) {
|
||||
$classname = WC_Product_Factory::get_product_classname( $product_id, $product_type );
|
||||
|
||||
return new $classname( $product_id );
|
||||
|
|
|
@ -741,19 +741,19 @@ class WC_Tests_Product_Functions extends WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test wc_get_product_classname().
|
||||
* Test wc_get_product_object().
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
public function test_wc_get_product_classname() {
|
||||
$this->assertInstanceOf( 'WC_Product_Simple', wc_get_product_classname( 'simple' ) );
|
||||
$this->assertInstanceOf( 'WC_Product_Grouped', wc_get_product_classname( 'grouped' ) );
|
||||
$this->assertInstanceOf( 'WC_Product_External', wc_get_product_classname( 'external' ) );
|
||||
$this->assertInstanceOf( 'WC_Product_Variable', wc_get_product_classname( 'variable' ) );
|
||||
$this->assertInstanceOf( 'WC_Product_Variation', wc_get_product_classname( 'variation' ) );
|
||||
public function test_wc_get_product_object() {
|
||||
$this->assertInstanceOf( 'WC_Product_Simple', wc_get_product_object( 'simple' ) );
|
||||
$this->assertInstanceOf( 'WC_Product_Grouped', wc_get_product_object( 'grouped' ) );
|
||||
$this->assertInstanceOf( 'WC_Product_External', wc_get_product_object( 'external' ) );
|
||||
$this->assertInstanceOf( 'WC_Product_Variable', wc_get_product_object( 'variable' ) );
|
||||
$this->assertInstanceOf( 'WC_Product_Variation', wc_get_product_object( 'variation' ) );
|
||||
|
||||
// Test incorrect type.
|
||||
$this->assertInstanceOf( 'WC_Product_Simple', wc_get_product_classname( 'foo+bar' ), 10 );
|
||||
$this->assertInstanceOf( 'WC_Product_Simple', wc_get_product_object( 'foo+bar' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue