Apply wc_get_product_classname() in the current code base
This commit is contained in:
parent
24c5bf41c8
commit
ba0773d12e
|
@ -453,7 +453,7 @@ class WC_Meta_Box_Product_Data {
|
|||
continue;
|
||||
}
|
||||
$variation_id = absint( $_POST['variable_post_id'][ $i ] );
|
||||
$variation = new WC_Product_Variation( $variation_id );
|
||||
$variation = wc_get_product_classname( '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 = new WC_Product_Variable( $product_id ); // Forces type to variable in case product is unsaved.
|
||||
$variation_object = new WC_Product_Variation();
|
||||
$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' );
|
||||
$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 = new WC_Product_Variation( $single_product->post->ID );
|
||||
$variation = wc_get_product_classname( '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 = new WC_Product_Variation();
|
||||
$variation = wc_get_product_classname( 'variation' );
|
||||
$variation->set_parent_id( $product->get_id() );
|
||||
$variation->set_attributes( $possible_attribute );
|
||||
$variation_id = $variation->save();
|
||||
|
|
|
@ -173,13 +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 ) );
|
||||
}
|
||||
|
||||
$classname = WC_Product_Factory::get_classname_from_product_type( $data['type'] );
|
||||
|
||||
if ( ! class_exists( $classname ) ) {
|
||||
$classname = 'WC_Product_Simple';
|
||||
}
|
||||
|
||||
$product = new $classname( $id );
|
||||
$product = wc_get_product_classname( $data['type'], $id );
|
||||
} elseif ( ! empty( $data['id'] ) ) {
|
||||
$product = wc_get_product( $id );
|
||||
|
||||
|
@ -195,7 +189,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
$product = new WC_Product_Simple( $id );
|
||||
$product = wc_get_product_classname( '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 = new WC_Product_Simple();
|
||||
$product = wc_get_product_classname( '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 = new WC_Product_Simple();
|
||||
$product = wc_get_product_classname( '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 = new WC_Product_Simple();
|
||||
$product = wc_get_product_classname( 'simple' );
|
||||
$product->set_name( 'Import placeholder for ' . $id );
|
||||
$product->set_status( 'importing' );
|
||||
$product->add_meta_data( '_original_id', $id, true );
|
||||
|
|
Loading…
Reference in New Issue