• I’ve been looking for a solution for several days without success, hope you guys can help me with that.

    I developed a script to import Products into WooCommerce for a client which specific attributes and variable products. The point is that, after I execute the script, I get successful results looking into the DB (all products, attributes and variations as properly imported), however when I go to the Dashboard and click on “Variations” tab in one of the products imported, the attributes are not set to each variation.

    However, when I save it MANUALLY (hit UPDATE button at the post), all the data is populated properly, just like it’s in the DB.

    So I decided to execute a command just after the script imports all the products to Update the Post for all products:

    $product = get_page_by_title( $consulta['produto'], OBJECT, 'product' );
                if( $product && is_object( $product ) ) {
                    $_product = wc_get_product( $product->ID );
                    $_product->variable_product_sync();
                    do_action( 'edit_post', $product->ID, $product );
                    do_action( 'edit_post_product', $product->ID, $product );
                    do_action( "save_post_product", $product->ID, $product, null );
                    do_action( 'save_post', $product->ID, $product, null );
                    do_action( 'pre_post_update', $product->ID );
                    $my_post = array(
                        'ID'           => $product->ID,
                        'post_title'   => $product->post_title,
                    );
                    // Update the post into the database
                    wp_update_post( $my_post );

    But I’m not getting the result I need unfortunately and I can’t find much details on the hooks to save (update) the products after importing them to the WooCommerce.

    I appreciate any help on that.

  • The topic ‘WooCommerce – Question on how to execute "Save Post" in PHP Script’ is closed to new replies.