5th Year Anniversary Super Sale! Save Upto 50% OFF*

Share your purchase on Social Media Woocommerce

By blog

We are here to share your purchase on social media with the glad of your website.

add this code into functions.php.,


add_action( 'woocommerce_thankyou', 'new_share_purchase_twitter', 5 );
 
function new_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 '</pre>
<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 class="alignleft twitter-prod-img" src="' . $image[0] . '" width="100" height="100" />'; } 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" href="https://twitter.com/intent/tweet?text=<?php echo $string ?>&url=https://yoursite.com/bloomer-armada/&hashtags=BloomerArmada,WooCommerce" target="_blank" rel="noopener"><img class="twitter-prod-tw-icon" src="https://yoursite.com/wp-content/uploads/2017/03/Twitter_Logo_White_On_Image.png" width="25" height="25" /> Share your purchase on Twitter → </a></div>
&nbsp;

</div>
&nbsp;

</div>
<?php } } 

add this code into style.css.,


.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;
}

Tagged under:

Show Buttons
Hide Buttons