• Resolved ilyapokrov

    (@ilyapokrov)


    Tell me, please. I encountered the following problem when updating products.

    I use this code so that products that have disappeared from the file are not deleted from my site, but are hidden from the catalog:

    function my_is_post_to_delete( $is_post_to_delete, $post_id, $import ) {
        if ( $product = wc_get_product( $post_id ) ) {
            $product->set_catalog_visibility( 'hidden' );
            $product->save();
        }
        return false;
    }
    add_filter( 'wp_all_import_is_post_to_delete', 'my_is_post_to_delete', 10, 3 );

    I also check the “Update all data” checkbox so that when these products appear in the file again, the visibility in the catalog changes to visible.

    This code works great!

    But there is a problem when I started using custom fields.

    A custom “In stock” field is added to all products. When the product is not available, it changes to “Out of stock”. But when the product reappears, an error appears in the file. First, the visibility in the catalog does not change, and second, the custom field does not change.

    This problem can be solved by unchecking the checkbox “Skip posts if their data in your file has not changed”.

    But in this case, the speed of import slows down, as several thousand goods. What did I do wrong? Where was the mistake made?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom fields when updating’ is closed to new replies.