• 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)
  • Hey there, @neversaynever504! Thanks for contacting us.

    While we can’t provide support for code customization as per our support policy, we do our best to offer advice and direct you to appropriate resources.

    You can visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there too.

    I’m going to leave it open for a bit to see if anyone is able to chime in and help you out further.

    Please let us know if there’s anything else we can do to help or if you have any questions.

    Have a wonderful day!

Viewing 1 replies (of 1 total)
  • The topic ‘Troubleshooting External Product Links in WooCommerce Gutenberg Blocks’ is closed to new replies.