Development and Design

How to insert Addthis Sharing Button in WooCommerce Product Short Description

Written by Sakthi Tharan

I have a website running on WordPress with  WooCommerce. AddThis is always my favorite tool of choice when it comes to social sharing. When I installed AddThis on the site, it displayed the share buttons under the ‘Product Description’ section. But I want to show the share buttons immediately after product summary. Just under ‘Add to Cart’ button. Unfortunately, AddThis couldn’t insert the social sharing buttons just below the ‘Product Short Description’ section. While many other sharing plugins can do that.

I tried editing my theme files and succeeded. It is just one way how to do that. Copy the content-single-product.php from wp-content/plugins/woocommerce/templates/ and pasting in theme’s woocommerce directory (/wp-content/themes/your-theme-name/woocommerce/). Now open the file from the new location and insert the AddThis code.

In case if you’re new to AddThis, below screenshot will show you from where to copy the code. Go to Addthis.com(sign in, register your site, install addthis plugin), select ‘Inline Share’ from ‘TOOLS’ tab at the top, then code will be in ‘GET THE CODE’ section.

Code From “GET THE CODE” section in Addthis.com Dashboard.

Another simple way is to write a function to add the code and hook it into ‘WooCommerce Share’. If you are doing this, you don’t have to do the above steps.

function insert_addthis_buttons() {
?>
// Paste the code copied from AddThis. 
<?php
}
add_action( 'woocommerce_share', 'insert_addthis_buttons' );

Copy above code and paste it in your theme’s ‘functions.php’ file. (wp-content/themes/your-theme-name/functions.php). Paste it in the last line before the php close tag ?> if it has one.

Everytime you update your theme you have to do this again, because your functions.php file will be repalced by new files when the theme is upgraded. If you don’t want to do that then use ‘functionality’ plugin method, which I will explain you in upcoming blogposts.

About the author

Sakthi Tharan

Alpha Geek | Blogger by interest | Former Web Developer & Designer | Research Scholar | Likes to share what he learned.