Troubleshooting External Product Links in WooCommerce Gutenberg Blocks
-
Hello, I’m currently utilizing this code to enable external links as product links for external product types. When users click on the product, it directly takes them to the external pages.
This functionality works seamlessly on category pages and WooCommerce short pages. However, it’s not functioning as expected with WooCommerce product blocks in Gutenberg.
I’ve searched around for solutions but haven’t found any previous discussions on this topic. Could you please assist me in adapting this code to work with product blocks in Gutenberg?
// Remove the default action that adds the product link add_action('init', function () { remove_action('woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open'); }); // Add a custom action to generate the external product link add_action('woocommerce_before_shop_loop_item', function () { global $product; // Check if the product is external if ($product->is_type('external')) { // Get the external product URL $external_url = $product->get_product_url(); // Output the external product link echo '<a href="' . $external_url . '">'; } else { // Output the regular product link woocommerce_template_loop_product_link_open(); } }, 20);
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Troubleshooting External Product Links in WooCommerce Gutenberg Blocks’ is closed to new replies.