In this article I will explain how to display social sharing links in single product page without using any plugin.
This can be done using “woocommerce_share” action. This action is called by WooCommerce in the single product page.
Put the below code in your theme/child-theme functions.php
function theme_prefix_woocommerce_share() {
global $post;
$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail = $thumbnail_id ? urlencode(current(wp_get_attachment_image_src($thumbnail_id, ‘large’))) : ”;
$title = esc_attr($post->post_title);
$permalink = urlencode(get_permalink($post->ID));
?>
<div class=”social”>
<a href=”https://twitter.com/intent/tweet?url=<?php echo $permalink; ?>&text=<?php echo $title; ?>” target=”_blank”>
Twitter
</a>
|
<a href=”https://www.facebook.com/sharer/sharer.php?u=<?php echo $permalink; ?>” target=”_blank”>
Facebook
</a>
|
<a href=”https://plus.google.com/share?url=<?php echo $permalink; ?>” target=”_blank”>
Google+
</a>
|
<a href=”http://pinterest.com/pin/create/button/?url=<?php echo $permalink; ?>&media=<?php echo $thumbnail; ?>&description=<?php echo $title; ?>” target=”_blank”>
Pinterest
</a>
|
<a href=”http://www.linkedin.com/shareArticle?mini=true&url=<?php echo $permalink; ?>&title=<?php echo $title; ?>” target=”_blank”>
LinkedIn
</a>
|
<a href=”http://www.tumblr.com/share?v=3&u=<?php echo $permalink; ?>&t=<?php echo $title; ?>” target=”_blank”>
Tumblr
</a>
</div>
<?php
}
add_action(‘woocommerce_share’, ‘theme_prefix_woocommerce_share’);
Hope this helps.