Ecommerce Shopify WordPress Discussion

How to Redirect Affiliate Products on WooCommerce Handpicked Gutenberg Products Block

I'm currently working with the WooCommerce Handpicked Products Gutenberg block on my WordPress website. I'm trying to implement functionality where the products displayed in this block, which are affiliate products, redirect users to their respective affiliate URLs when clicked on the product title or image. I've tried implementing custom code to modify the behavior of the block, but I'm encountering difficulties. Currently, only the button redirects to the affiliate URL. I've been successful in implementing similar functionality on WooCommerce archive pages, but it's not working as expected for the Handpicked Products block when trying to add in the blog posts. Could someone provide guidance or suggest where I might be going wrong with my implementation? Here's a simplified version of what I've attempted so far: remove_action('woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open'); add_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 15); add_action('woocommerce_before_shop_loop_item', 'woocommerce_add_aff_link_open', 10); add_action('woocommerce_before_shop_loop_item_title', 'woocommerce_add_aff_link_close', 10); function woocommerce_add_aff_link_open(){ $product = wc_get_product(get_the_ID()); if ($product->is_type('external')) echo '<a href="' . $product->get_product_url() . '" class="wp-block-handpicked-products">'; } function woocommerce_add_aff_link_close(){ $product = wc_get_product(get_the_ID()); if ($product->is_type('external')) echo '</a>'; }
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.