In the WP Social plugin, specifically in the share.php
file (line 406), there was an issue with how the URL for sharing a product was generated on product pages. The problem occurred when individual product blocks were placed on pages with more than 10 products. In these cases, each product block contained a shortcode with social media buttons, but the URL generated was not always correct for the specific product. Instead of providing a unique URL for each product, the plugin was generating a shared URL based on the current page’s URL (for example, page 4 or page 5 with a generic title
of the product, rather than a link directly to the product).
This caused confusion for users and hindered proper social media sharing for individual products, as they were sharing the link to the page rather than the direct link to the product itself.
Analysis:
Upon reviewing the problematic line in the share.php
file:
$currentUrl = (isset($_SERVER['HTTPS']) && sanitize_text_field($_SERVER['HTTPS']) === 'on' ? 'https' : 'http') . '://' . sanitize_text_field($_SERVER['HTTP_HOST']) . sanitize_url($_SERVER['REQUEST_URI']);
This line was constructing the URL using the current page’s URL, which works fine in many cases but fails when a product block is embedded within a page that lists multiple products. Here, the page’s URL (e.g., page/2
or page/3
) was used, leading to incorrect sharing links for individual products.
Temporary Solution:
To address this issue, I implemented the following condition:
$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 code ensures that if the current post is a product (via the get_post_type($postId)
check), it will use the correct product permalink (get_permalink($postId)
). Otherwise, it will fallback to using the current page’s URL as before. This provides the correct sharing URL when a product is on a page with multiple product blocks, ensuring that each product has a unique URL to share.
Benefits of the Solution:
Temporary Nature of the Solution:
This solution is a temporary fix that I implemented to ensure the correct URL is passed for product pages while still using the existing behavior for other pages. I hope this improvement will be included in future updates of the WP Social plugin so that I no longer need to patch this line myself. Ideally, a hook could be added for easier customization, allowing developers to override this behavior without needing to modify the core plugin files.
Why This Is Important:
For those using the plugin on product pages where multiple products are listed, it is crucial to ensure that each product’s URL is shared correctly. Without this fix, social media sharing would point to a generic page URL instead of the specific product link. This is particularly important for websites that rely on e-commerce features, as it allows users to share specific products, driving more accurate traffic and improving product visibility.
By implementing this fix, I was able to make sure that each product block has a unique shareable URL, making the sharing experience more effective for both users and site owners.
]]>I hope you’re doing well.
I’m using your plugin and encountered a few issues I’d like assistance with. Below are the details, along with links to screenshots for reference:
I’d greatly appreciate your guidance on resolving these issues. Thank you for your support!
]]>SS
Similar to the problem https://www.ads-software.com/support/topic/error-please-select-some-product-options/ .
But i don’t want to downgrade back to WooCommerce Payments 6.1.1.
Unfortunately, I was unable to reproduce the problem on Chrome. So i couldn’t dig deeper on this problem.
Thank you in advance for any help or suggestions you can give to resolve this.
I would appreciate if someone could help me out with this issue.
]]>