Import works only for the first products variations
-
Hi,
I use this function for updating a custom field to each variations but after import, only the first product variations is created/updated. It doesn’t continue the process. All the others products are not being updated.
Could you help me?
add_action( ‘pmxi_saved_post’, ‘my_set_variations’, 10, 3 );
function my_set_variations( $id, $xml, $u ) {
$product = wc_get_product( $id );
if ( ! $product ) return;
if ( ! $product->is_type( ‘variable’ ) ) return;$record = json_decode( json_encode( (array) $xml ), 1 );
$i = 0;
while( array_key_exists( $i, $record[‘variants’][‘variant’] ) ) {
if ( $product_id = wc_get_product_id_by_sku( $record[‘variants’][‘variant’][ $i ][‘sku’] ) ) {
update_post_meta( $product_id, ‘some_custom_field’, $record[‘variants’][‘variant’][ $i ][‘custom_field_element’] );
}
$i++;
}
}`
- The topic ‘Import works only for the first products variations’ is closed to new replies.