WooCommerce duplicate product, update properties
-
I’m trying to duplicate a variable product and update a handful of properties.
When I run this function, the product status is “Draft” and the stock is listed as “Out of Stock”, while all of the variations have the correct Regular Price and Stock quantity and Managed stock? Is checked.
I tried setting these properties before the product is saved with woocommerce_product_duplicate_before_save, but this hook is executed several times, once for the parent product and again for each variation.
I’ve also tried selecting the most recently created product with WC_Product_Query. The correct product is selected, but the properties are unchanged before and after the set methods are executed.function test_dupproduct(){
$product = wc_get_product( '1000' );
//woocommerce_product_duplicate_before_save
$wc_adp = new WC_Admin_Duplicate_Product;
$dupproduct = $wc_adp->product_duplicate( wc_get_product( $product ) );
$dupproduct = $query->get_products();
$dupproduct->set_sku( '99999' );
$dupproduct->set_name( 'Product Name' );
$dupproduct->set_short_description('Product Short Description');
$dupproduct->set_status( 'Published' );
}
The topic ‘WooCommerce duplicate product, update properties’ is closed to new replies.