Hi@chengjianping,
You can add social share buttons to a single product page with the following code snippet. This example includes links for 4 social platforms, and you can add more as needed. To ensure the changes persist through theme updates, add this code to your child theme’s functions.php
file or use a code snippet plugin.
add_action('woocommerce_share', 'custom_woocommerce_share_buttons', 45);
function custom_woocommerce_share_buttons() {
global $product;
$product_url = get_permalink($product->get_id());
$product_title = get_the_title($product->get_id());
$share_text = 'Check out this product: ';
?>
<div class="custom-share-buttons">
<h3>Share this product</h3>
<a href="https://www.facebook.com/sharer.php?u=<?php echo urlencode($product_url); ?>" target="_blank">Share on Facebook | </a>
<a href="https://twitter.com/share?url=<?php echo urlencode($product_url); ?>&text=<?php echo urlencode($share_text . $product_title); ?>" target="_blank">Share on Twitter |</a>
<a href="https://www.linkedin.com/shareArticle?mini=true&url=<?php echo urlencode($product_url); ?>&title=<?php echo urlencode($product_title); ?>" target="_blank">Share on LinkedIn |</a>
<a href="mailto:?subject=<?php echo urlencode($product_title); ?>&body=<?php echo urlencode($share_text . $product_url); ?>">Share via Email</a>
</div>
<?php
}
This code snippet will add social share buttons on single product pages [screenshot]. Customize the social share links and icons as needed.
Regards