Conceptually, you are on the right track with the second snippet.
- You MUST use exit(); after a wp_redirect() call
However, looking at the Woocommerce documentation, is_product()
does not accept any arguments. This means passing '7854' in is_product(7854)
is meaningless to the function. It returns a boolean (true|false) based on whether you are viewing a single product, regardless of which product.
Looking at the documentation for is_product_tag()
I think that if you substituted is_product_tag( 'your-product-slug' )
that would work.