• Resolved chosendaone

    (@chosendaone)


    I use rest API to manage the store. It connects correctly, I can add new products. Unfortunately, there is a problem with product updates, such that other plugins do not see the changes. Only by manually clicking update on the product, makes the changes visible. Is there any action that will simulate / force such an update after changes made by the API.

    The problem has other plugins but is the same for each, (ACF fields, WP Gridbuilder filtering) in each case it is necessary to manually update the changes, despite the fact that those on the product page display correctly.

    Example: I change the attribute color of the product to black through the API, then on the product edit page and on the product page these changes are visible, but WP Gridbuilder filters will not notice this change. The same is true for ACF fields. Clicking update solves the problem.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hey there, @chosendaone! Thanks for contacting us. I’m happy to help you.

    To confirm, if you disable WP Gridbuilder filters and ACF fields (and any other plugin that interferes with the product or product page), are you able to see the changes on the front end?
    The reason I’m asking is to see if the issue is happening with WooCommerce core.

    If you are not able to replicate the issue with only WooCore, please reach out to the third-party plugins support channels, as they will be better suited to assist with their plugin.

    If you are able to replicate this with only WooCommerce, please let us know so we can assist you further.

    Please let us know how it goes.

    Have a wonderful day!

    Thread Starter chosendaone

    (@chosendaone)

    Well in case of WPGridbuilder the changes are visible on product page. I mean if change color from black to red, it is visible in product tab as red, but in filters there is still black value until manual update of product.

    I cant say about ACF because without plugin there are no fields to show.

    I wonder if is it possible to simulate /force manual update after any API action?

    I was trying to add this code but without results:

    add_action('woocommerce_rest_insert_product', 'handle_product_update', 10, 3);
    
    function handle_product_update($product, $request, $creating) {
        $product_id = $product->get_id();
    
        $post_data = array(
            'ID'            => $product_id,
            'post_status'   => 'publish',
            'post_type'     => 'product',
        );
        wp_update_post($post_data);
    
        $product = wc_get_product($product_id);
        $product->save();
    
        clean_post_cache($product_id);
        wp_cache_flush();
    
        if (function_exists('acf_save_post')) {
            acf_save_post($product_id);
        }
    
        do_action('woocommerce_update_product', $product_id);
    
        $attributes = $product->get_attributes();
        if (!empty($attributes)) {
            foreach ($attributes as $attribute) {
                if (is_object($attribute) && method_exists($attribute, 'get_id')) {
                    wp_update_term($attribute->get_id(), $attribute->get_taxonomy());
                }
            }
        }
    
        flush_rewrite_rules();
    }
    
    function update_product_meta($product_id, $meta_key, $meta_value) {
        update_post_meta($product_id, $meta_key, $meta_value);
        do_action('updated_post_meta', $meta_key, $meta_value, $product_id);
    }
    • This reply was modified 5 months, 3 weeks ago by chosendaone.
    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @chosendaone

    I change the attribute color of the product to black through the API, then on the product edit page and on the product page these changes are visible, but WP Gridbuilder filters will not notice this change. The same is true for ACF fields. Clicking update solves the problem.

    It seems like the issue might be related to the caching mechanism of the plugins you’re using, not updating immediately after a change is made via the API.

    This is a third-party plugin, and we don’t provide help & support for 3rd-party plugins or themes as they’re outside our support scope. It would be best to reach out to the WP Gridbuilder and ACF plugin developer for further assistance.

    Additionally, the code snippet you’ve shared seems correct. It’s trying to manually update the product and clear the cache after a product is updated via the REST API. However, the issue might be related to the sequence of actions or the specific actions you’re trying to use. You can try the following:

    add_action('woocommerce_rest_insert_product', 'handle_product_update', 10, 3);
    
    function handle_product_update($product, $request, $creating) {
    $product_id = $product->get_id();
    
    wp_update_post(array('ID' => $product_id));
    
    wc_delete_product_transients($product_id);
    
    if (function_exists('acf_save_post')) {
    acf_save_post($product_id);
    }
    
    do_action('woocommerce_update_product', $product_id);
    
    $attributes = $product->get_attributes();
    if (!empty($attributes)) {
    foreach ($attributes as $attribute) {
    if (is_object($attribute) && method_exists($attribute, 'get_id')) {
    wp_update_term($attribute->get_id(), $attribute->get_taxonomy());
    }
    }
    }
    flush_rewrite_rules();
    }

    Please note that writing or providing custom code is not within the scope of our support policy. If you are still having problems, we recommend asking development questions on the #developers channel of the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

    Thread Starter chosendaone

    (@chosendaone)

    Thank you very much, it works that way. I’ve another problem with API maybe u can help without creating new topic.

    I think its Woocoomerce.

    I want to sort attributes in my own way, but it dosent work. In attribute option setting is set to “own sorting” but somehow it dosent work.

    So here is how it looks on my json:

    buton the product page – 1:12x 1.2 TV SAS 2.5″ is displayed before “4x 1.92TB SAS 2.5” can i change something in json? As i said on the web sorting is set to “own”

    Plugin Support omarfpg a11n

    (@omarfpg)

    Hi @chosendaone,

    I’m glad we were able to help! @shameemreza rocks!

    Regarding your next query, kindly start a new thread, please, so we can keep the forums in order, this will allow others searching for help in specific topics to find it easier! ??

    PS: if you have a few minutes, we’d love if you could leave us a review here:?https://www.ads-software.com/support/plugin/woocommerce/reviews/.

    Cheers!
    -OP

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.