|
<?php |
|
/* |
|
Plugin Name: OFC Sharing Buttons |
|
Description: sharing buttons for content |
|
Version: 0.1 |
|
License: GPL |
|
Author: Ruben Madila |
|
Author URI: ollieford.co.uk |
|
*/ |
|
|
|
function ofc_social_sharing_buttons($content) { |
|
if ( !class_exists( 'WooCommerce' ) ) { |
|
return; |
|
} |
|
|
|
global $post, $product; |
|
|
|
// Get current page URL |
|
$ofcURL = urlencode($product->get_permalink()); |
|
|
|
// Get current page title |
|
$ofcTitle = str_replace( ' ', '%20', $product->get_title()); |
|
|
|
// Get Post Thumbnail for pinterest |
|
$ofcThumbnail = wp_get_attachment_image_src( $product->get_image_id(), 'full' ); |
|
|
|
// Construct sharing URL without using any script |
|
$twitterURL = 'https://twitter.com/intent/tweet?text='.$ofcTitle.'&url='.$ofcURL.'&'; |
|
//$twitterURL .= ';via=ofc'; |
|
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$ofcURL; |
|
//$googleURL = 'https://plus.google.com/share?url='.$ofcURL; |
|
//$bufferURL = 'https://bufferapp.com/add?url='.$ofcURL.'&text='.$ofcTitle; |
|
$whatsappURL = 'whatsapp://send?text='.$ofcTitle . ' ' . $ofcURL; |
|
//$linkedInURL = 'https://www.linkedin.com/shareArticle?mini=true&url='.$ofcURL.'&title='.$ofcTitle; |
|
|
|
// Based on popular demand added Pinterest too |
|
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$ofcURL.'&media='.$ofcThumbnail[0].'&description='.$ofcTitle; |
|
|
|
// Add sharing button at the end of page/page content |
|
$content .= '<!-- ofc.com social sharing. Get your copy here: http://ofc.me/1VIxAsz -->'; |
|
$content .= '<div class="ofc-social">'; |
|
$content .= '<h5>Share On</h5>'; |
|
$content .= '<a class="btn btn-border ofc-social-link ofc-twitter mr-2 mb-1" href="'. $twitterURL .'" target="_blank"><i class="fa fa-twitter mr-1"></i> Twitter</a>'; |
|
$content .= '<a class="btn btn-border ofc-social-link ofc-facebook mr-2 mb-1" href="'.$facebookURL.'" target="_blank"><i class="fa fa-facebook mr-1"></i> Facebook</a>'; |
|
$content .= '<a class="btn btn-border ofc-social-link ofc-whatsapp d-inline-block d-sm-none mr-2 mb-1" href="'.$whatsappURL.'" target="_blank"><i class="fa fa-whatsapp mr-1"></i> WhatsApp</a>'; |
|
//$content .= '<a class="ofc-link ofc-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>'; |
|
//$content .= '<a class="ofc-link ofc-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>'; |
|
//$content .= '<a class="ofc-link ofc-linkedin" href="'.$linkedInURL.'" target="_blank">LinkedIn</a>'; |
|
$content .= '<a class="btn btn-border ofc-social-link ofc-pinterest mb-1" href="'.$pinterestURL.'" data-pin-custom="true" target="_blank"><i class="fa fa-pinterest mr-1"></i> Pin It</a>'; |
|
$content .= '</div>'; |
|
|
|
echo $content; |
|
|
|
}; |
|
add_action( 'woocommerce_share', 'ofc_social_sharing_buttons'); |