Skip to content

Commit cd13791

Browse files
Set correct post type for product variation
And catch any WC_Data_Exception
1 parent 3ebda4a commit cd13791

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

includes/import/abstract-wc-product-importer.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,21 @@ protected function get_product_object( $data ) {
173173
return new WP_Error( 'woocommerce_product_importer_invalid_type', __( 'Invalid product type.', 'woocommerce' ), array( 'status' => 401 ) );
174174
}
175175

176-
$product = wc_get_product_object( $data['type'], $id );
176+
try {
177+
// Prevent getting "variation_invalid_id" error message from Variation Data Store.
178+
if ( 'variation' === $data['type'] ) {
179+
$id = wp_update_post(
180+
array(
181+
'ID' => $id,
182+
'post_type' => 'product_variation',
183+
)
184+
);
185+
}
186+
187+
$product = wc_get_product_object( $data['type'], $id );
188+
} catch ( WC_Data_Exception $e ) {
189+
return new WP_Error( 'woocommerce_product_csv_importer_' . $e->getErrorCode(), $e->getMessage(), array( 'status' => 401 ) );
190+
}
177191
} elseif ( ! empty( $data['id'] ) ) {
178192
$product = wc_get_product( $id );
179193

0 commit comments

Comments
 (0)