73
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 Get tutoraspire.com FREE * @sourcecode https://tutoraspire.com/?p=22104 * @author Tutor Aspire * @compatible Woo 3.5.3 * @donate $9 https://tutoraspire.com */ add_action( 'woocommerce_thankyou', 'tutoraspire_share_purchase_twitter', 5 ); function tutoraspire_share_purchase_twitter( $order_id ) { // CREATE TWEET CONTENT $string = 'I%20just%20became%20an%20official%20Business%20Bloomer%20Supporter!%20Check%20out%20the%20benefits%20at:%20'; // SEE WHICH PRODUCTS ARE IN THE ORDER $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 ); } // GET THE LAST PRODUCT AND SEE IF BELONG TO WANTED LIST $barmada = array( "21665", "21657", "21650" ); if ( in_array( $product_id, $barmada ) ) { // IF YES, CREATE THE THANK YOU PAGE "TWITTER BOX" echo 'Share your purchase with the WooCommerce community!
'; echo ''; echo ''; if ( has_post_thumbnail( $product_id ) ) { $image = wp_get_attachment_image_src( get_post_thumbnail_id( $product_id ), 'single-post-thumbnail' ); echo ''; } echo '' . $product_name . ''; echo '' . $product_url . ''; echo ''; // GENERATE THE CLICK TO TWEET A HREF, NOTE "$string" ?> &url=https://tutoraspire.com&hashtags=BloomerArmada,WooCommerce"> Share your purchase on Twitter →And as I feel generous today, here’s the full CSS I used as well 🙂
/* THANK YOU PAGE TWITTER */ .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; }