Fix for Incorrect Product URL Sharing
-
I encountered a problem when I tried to integrate, or rather, add a Sharing panel to the product blocks on the page. However, it uses the actual pages like page 1, 2, 3, and so on. The issue is that in
share.php
, on line 406, the link was being generated based solely on the current page. Many people like me, or perhaps others, would want to use social sharing not just on the full product or WordPress post pages, but also on any product block, for example, when there are several products on a page. My solution was to create a condition to address these needs. I hope you will include this fix in the next update, as it is quite simple.$currentUrl = ''; if ( 'product' === get_post_type($postId) ) { // If it's a product, get the correct permalink $currentUrl = get_permalink($postId); } else { // If it's not a product, use the current page's URL $currentUrl = (isset($_SERVER['HTTPS']) && sanitize_text_field($_SERVER['HTTPS']) === 'on' ? 'https' : 'http') . '://' . sanitize_text_field($_SERVER['HTTP_HOST']) . sanitize_url($_SERVER['REQUEST_URI']); }
This is a good solution to all the issues.
- You must be logged in to reply to this topic.