WooCommerce: “Share your Purchase on Twitter” @ Thank You Page

Boom! I was thinking of a way to show a “Share your Purchase on Social Media” on my thank you page right after someone becomes an official supporter. So, I spent some time coding and – as always – now I’m going to spend some more time to share my hard work!

Leave a comment below if this was helpful – and if you want to test this out, you’re very welcome to become an official Business Bloomer fan of course 🙂

PHP Snippet: Display a “Share your Purchase on Twitter” button @ WooCommerce Thank You Page

 * @snippet       Display a "Share your Purchase on Twitter" button @ WooCommerce Thank You Page
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=22104
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 2.6.14
add_action( 'woocommerce_thankyou', 'bbloomer_share_purchase_twitter', 5 );
function bbloomer_share_purchase_twitter( $order_id ) {
$string = 'I%20just%20became%20an%20official%20Business%20Bloomer%20Supporter!%20Check%20out%20the%20benefits%20at:%20';
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
    $product_id = $item['product_id'];
    $product_name = $item['name'];
    $product_url = get_permalink( $product_id );
$barmada = array("21665", "21657", "21650");
if (in_array($product_id, $barmada)) {
echo '<h2 class="twitter-prod-h2">Share your purchase with the WooCommerce community!</h2>';
echo '<div class="twitter-prod-wrapper"><div class="twitter-prod-div col2-set addresses">';
echo '<div class="col-1">';
if ( has_post_thumbnail( $product_id ) ) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $product_id ), 'single-post-thumbnail' );
echo '<img width="100" height="100" src="' . $image[0] . '" class="alignleft twitter-prod-img">';
echo '<div class="twitter-prod-name">' . $product_name . '</div>';
echo '<div class="twitter-prod-url"><small>' . $product_url . '</small></div>';
echo '</div><div class="col-2">';
<a class="button twitter-prod-button" target="_blank" href="https://twitter.com/intent/tweet?text=<?php echo $string ?>&url=https://businessbloomer.com/bloomer-armada/&hashtags=BloomerArmada,WooCommerce"><img width="25" height="25" src="https://businessbloomer.com/wp-content/uploads/2017/03/Twitter_Logo_White_On_Image.png" class="twitter-prod-tw-icon"> Share your purchase on Twitter &rarr; </a>

And as I feel generous today, here’s the full CSS I used as well 🙂

.twitter-prod-wrapper {
    overflow: hidden;
.twitter-prod-div {
border: 4px solid #4099FF;
padding: 1em 2em 0;
background: #fcfcfc;
.twitter-prod-div .col-1, .twitter-prod-div .col-2 {
margin-top: 1.618em;
.twitter-prod-name {
color: #4099FF;
font-weight: bold;
.twitter-prod-tw-icon {
display: inline-block;
vertical-align: middle;
.twitter-prod-button {
float: right;
background: #4099FF;
border-color: #4099FF;

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (and in case of CSS, this goes at the bottom of the style.css file) – if you need more guidance, please take a look at my site


Mostakim Hossen

I am Mostakim Hossain, a Web designer and developer, 23 years of age. I have been working as a freelance (upwork) for almost 2 years now and I will be glad in helping you create your next awesome project.

I have created lots of public and private websites(some shown below) and always looking for more work to learn from. I am using PHP as my primary programming language. You can see my skill set beside this text.

I am a person who is willing to learn and adapts quickly. I am keen to design and security. I believe in the core principles of Open Source and support it. I have a minimalist approach to design and usability. Simplicity is beauty they say.
Masters of Accountancy : Asian University of Bangladesh
I’m here to answer any questions you might have about our products and services. Feel free to contact me using any of the following methods:

Email : support@smarterdevs.com

Leave a Reply

Your email address will not be published. Required fields are marked *


Coupon : happynewyear

60% OFF

Stay updated with all latest updates,upcoming plugins & much more.
WordPress Themes