How to prevent woocommerce product tag field from update?

To ensure that the special tags on your WooCommerce products remain unchanged during the update process, you’ll need to modify your function to check for these tags and preserve them. Since you’re using a crawler to update the products, the function can be tailored to ignore tag updates for products that have these special tags.

Here’s a modified version of your function that should help with this:

add_action('woocommerce_update_product', 'on_update_product', 10, 2);
function on_update_product($product_id, $product){
    // Define your special tag(s) here
    $special_tags = ['special-tag-1', 'special-tag-2']; // Replace with your actual tag slugs

    // Get current product tags
    $current_tags = get_the_terms($product_id, 'product_tag');

    // Check if current product has any of the special tags
    $has_special_tag = false;
    if (!empty($current_tags)) {
        foreach ($current_tags as $tag) {
            if (in_array($tag->slug, $special_tags)) {
                $has_special_tag = true;
                break;
            }
        }
    }

    // If the product has a special tag, preserve these tags
    if ($has_special_tag) {
        $tag_ids = array_map(function($tag) { return $tag->term_id; }, $current_tags);
        wp_set_object_terms($product_id, $tag_ids, 'product_tag');
    }

    // Continue with other update processes if needed
    // ...
}

In this code:

You define the special tags you want to preserve.
Before updating the product, it checks if the product has any of these special tags.

If the product has a special tag, the function preserves these tags by reapplying them.

Make sure to replace special-tag-1, special-tag-2 with the actual slugs of your special tags. This function is triggered during the product update process, and it will ensure that if a product has one of the specified special tags, those tags won’t be altered during the update.

casinojojobetpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casinocanlı bahis casino siteleriOnwin Güncel Girişholiganbetholiganbet girişholiganbet güncel giriş