Can't update the shipping amount while checkout in woocommerce(wordpress) - wordpress

I am trying to add shipping cost to the current order with a custom plugin code. I have write a plugin to display some radio buttons for delivery option and pickup option and embed one javascript file for the radio check event. The following is my plugin code:
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
function radio_button_checks(){
wp_register_script('wp_head',plugin_dir_url(__FILE__).'radio_check.js',array( 'jquery' ), '1.0', true);
wp_enqueue_script('wp_head');
}
function delivery_form() {
$content = '<div style="width:90%; margin-top:10px; float:left; background-color:rgba(255, 255, 255, 0.85); border-radius:5px; padding:5%;">';
$content .= '<h3 id="first-self-id"><input type="radio" value="self_product_pick_up" class="distance_between_text" name="delivery" id="self-delivery" />PICK UP AT THE TROPICAL FRUIT TRIBE HQ KICTHEN AT 1/1 GENERAL BRIDGES CREC, DACEYVILLE 2032</h2>';
$content .= '<div id="self-delivery-functionality" class="delivery_functionality" style="width: 100%; display: inline-block;">';
$content .= '<div class="self_delivery_day" style="width: 45%; float: left; padding: 0% 2%; text-align: right; ">';
$content .= '<h4><input type="radio" value="tuesday" class="distance_between_text" />TUE</h4>';
$content .= '</div>';
$content .= '<div class="self_delivery_time" style="width: 45%; float: left; padding: 0% 2%; text-align: left;">';
$content .= '<h4><input type="radio" name="pickup_time" value="9AM-12PM" class="distance_between_text" />9AM-12PM</h4>';
$content .= '<h4><input type="radio" name="pickup_time" value="12PM-3PM" class="distance_between_text" />12PM-3PM</h4>';
$content .= '<h4><input type="radio" name="pickup_time" value="3PM-6PM" class="distance_between_text" />3PM-6PM</h4>';
$content .= '<h4><input type="radio" name="pickup_time" value="6PM-8PM" class="distance_between_text" />6PM-8PM</h4>';
$content .= '</div>';
$content .= '</div>';
$content .= '<h3 id="second-notSelf-id"><input type="radio" value="shop_keeper_delivery" class="distance_between_text" checked="checked" name="delivery" id="other-one-deliver" />DELIVERY OPTION ($12 only)</h2>';
$content .= '<div id="seller-delivery-functionality" style="display:block;">';
$content .= '<div class="delivery-info-text" style="text-align: left;">';
$content .= '<p style="margin:5px; font-size:1em;">PLEASE KEEP IN MIND THAT THIS IS A FROZEN PRODUTS AND NEEDS TO BE STORED IN FREEZER IMMEDIATLY UPON DELIVERY. PLEASE ENSURE YOU ARE AVAILABLE TO TAKE THIS DELIVERY AT THE DROP OFF LOCATION SPECIFIED.</p>';
$content .= '</div>';
$content .= '<div class="delivery_functionality" style="width: 100%; display: inline-block;">';
$content .= '<div class="shop_keeper_delivery_day" style="width: 45%; float: left; padding: 0% 2%; text-align: right;">';
$content .= '<h4><input type="radio" name="delivery_day" value="monday" class="distance_between_text" />Mon</h4>';
$content .= '<h4><input type="radio" name="delivery_day" value="fri" class="distance_between_text" />Fri</h4>';
$content .= '</div>';
$content .= '<div class="shop_keeper_delivery_time" style="width: 45%; float: left; padding: 0% 2%; text-align: left;">';
$content .= '<h4><input type="radio" name="delivery_time" value="9AM-12PM" name="" class="distance_between_text" />9AM-12PM</h4>';
$content .= '<h4><input type="radio" name="delivery_time" value="12PM-3PM" class="distance_between_text" />12PM-3PM</h4>';
$content .= '<h4><input type="radio" name="delivery_time" value="3PM-6PM" class="distance_between_text" />3PM-6PM</h4>';
$content .= '<h4><input type="radio" name="delivery_time" value="6PM-8PM" class="distance_between_text" />6PM-8PM</h4>';
$content .= '</div>';
$content .= '</div>';
$content .= '</div>';
$content .= '<input type="hidden" id="shipping_rate" value="0.00" /> ';
$content .= '</div>';
echo $content;
}
add_action("woocommerce_after_cart_table","delivery_form");
add_action("wp_enqueue_scripts","radio_button_checks");
and my radio_check.js file contain the following code:
jQuery(document).ready(function(){
/* Checkout CheckBox Functionality for Self Delivery */
jQuery("#self-delivery-functionality").hide("slow");
jQuery("#seller-delivery-functionality").show("slow");
jQuery("#self-delivery").click( function() {
if(jQuery(this).is(':checked')) {
jQuery("#self-delivery-functionality").show("slow");
jQuery("#seller-delivery-functionality").hide("slow");
jQuery("#seller-delivery-functionality").find("input[type='checkbox']").prop("checked", false);
jQuery("#seller-delivery-functionality").find("input[type='radio']").prop("checked", false);
}
});
/* Checkout CheckBox Functionality for having Delivery Functionality */
jQuery("#other-one-deliver").click( function() {
if(jQuery(this).is(':checked')) {
jQuery("#seller-delivery-functionality").show("slow");
jQuery("#self-delivery-functionality").hide("slow");
jQuery("#self-delivery-functionality").find("input[type='checkbox']").prop("checked", false);
jQuery("#self-delivery-functionality").find("input[type='radio']").prop("checked", false);
}
});
jQuery('input[name=delivery_time]').click(function(){
if(jQuery(this).is(':checked'))
{
var curr_amount_dol = jQuery('.cart-subtotal .amount').html().replace('$','');
var total_amount = parseFloat(curr_amount_dol) + parseFloat(12.00);
//alert(total_amount.toFixed(2));
jQuery('#shipping_rate').val('$'+total_amount.toFixed(2));
jQuery('.order-total .amount').html('$'+total_amount.toFixed(2));
}
});
}); //ready function ends
This code is updating total amount (only displaying) along with shipping cost (which is $12) but when i click the checkout button i will not get the total amount with shipping rate on next page.
What should i more add in this code to update the shipping cost on the radio button checked?
Note: right now the total amount is updating through the javascript.

'woocommerce_cart_calculate_fees' solved my issue. I just added the following code and a little modification on my javascript.
function woo_add_cart_fee() {
$req = $_REQUEST['shipping_method'];
if($req=='delivery')
{
WC()->session->set('ship_val','12.00');
}
else if($req=='pickup')
{
WC()->session->set('ship_val','00.00');
}
//checkship($_REQUEST['shipping_method']);
WC()->cart->add_fee('Shipping ', WC()->session->get('ship_val'));
}
add_action('woocommerce_cart_calculate_fees', 'woo_add_cart_fee');
and for the javascript i just redirect the same page along with a query parameter 'shipping_method'
jQuery('input[name=delivery_time]').click(function(){
if(jQuery(this).is(':checked'))
{
window.location='http://examplesite.com/cart/?shipping_method=delivery';
}
});
jQuery('input[name=pickup_time]').click(function(){
if(jQuery(this).is(':checked'))
{
window.location='http://examplesite.com/cart/?shipping_method=pickup[';
}
});
On radio button checked my page is redirect with the query ?shipping_method=delivery / ?shipping_method=pickup
and my php code in the plugin file check the parameter value and set the shipping rate using:
add_action('woocommerce_cart_calculate_fees', 'woo_add_cart_fee');
and the fees is update on both cart page and checkout page too.

Related

Repeater Fields in Widget Form Function in Wordpress

I've been trying to add repeater fields in my wordpress widget form. I found two plugin examples but they don't work anymore. When I click on "Add row", nothing happens.
https://www.commoninja.com/discover/wordpress/plugin/social-repeater-widget
https://www.zealousweb.com/wordpress-plugins/repeater-entries-widget/
I noticed both use jquery in their widgets which I guess doesn't work anymore in the newer Wordpress versions?
/**
* Back-end widget form.
*
* #see WP_Widget::form()
*
* #param array $instance Previously saved values from database.
*/
public function form($instance)
{
$max_entries = get_option( 'max_entries' );
$max_entries = (empty($max_entries)) ? '5' : $max_entries;
$widget_add_id = $this->id . "-add";
$title = !empty($instance['title']) ? $instance['title'] : __('Social Repeater Widget', 'srw-widget');
$srw_html = '<p>';
$srw_html .= '<label for="'.$this->get_field_id('title').'"> '. __( 'Widget Title', 'srw-widget' ) .' :</label>';
$srw_html .= '<input id="'.$this->get_field_id('title').'" name="'.$this->get_field_name('title').'" type="text" value="'.$title.'" />';
$srw_html .= '<div class="'.$widget_add_id.'-input-containers"><div id="entries">';
for( $i =0; $i<$max_entries; $i++){
if(isset($instance['block-' . $i]) || isset($instance['social_platform-' . $i]))
{
$srw_tab_title = !empty($instance['social_platform-' . $i]) ? $instance['social_platform-' . $i] : __( 'Add Social Profile Details', 'srw-widget' );
$display = (!isset($instance['block-' . $i]) || ($instance['block-' . $i] == "")) ? 'style="display:none;"' : '';
$srw_html .= '<div id="entry'.($i+1).'" '.$display.' class="entrys"><span class="entry-title" onclick = "slider(this);"> '.$srw_tab_title.' </span>';
$srw_html .= '<div class="entry-desc cf">';
$srw_html .= '<input id="'.$this->get_field_id('block-' . $i ).'" name="'.$this->get_field_name('block-' . $i ).'" type="hidden" value="'.$instance['block-' . $i].'">';
$social_platform = esc_attr( $instance['social_platform-' . $i] );
$social_platform_link = esc_attr( $instance['social_platform_link-' . $i] );
$srw_html .= '<p class="last desc">';
$srw_html .= '<label for="'.$this->get_field_id('social_platform-' . $i).'"> '. __( 'Social Platform', 'srw-widget' ) .' :</label>';
$srw_html .= '<input class="widefat" id="'.$this->get_field_id('social_platform-' . $i).'" name="'.$this->get_field_name('social_platform-' . $i).'" type="text" value="'.$social_platform.'" placeholder="'.__( 'Enter Social Platform name', 'srw-widget' ).'" />';
$srw_html .= '</p><p>';
$srw_html .= '<label for="'.$this->get_field_id('social_platform_link-' . $i).'"> '. __('Social platform Link', 'srw-widget' ) .' :</label>';
$srw_html .= '<input class="widefat" id="'.$this->get_field_id('social_platform_link-' . $i).'" name="'.$this->get_field_name('social_platform_link-' . $i).'" type="url" value="'.$social_platform_link.'" placeholder="'.__( 'Enter Social Platform Link', 'srw-widget' ).'"/>';
$srw_html .= '</p>';
/* end wrapper with delete entry option */
$srw_html .= '<p><span class="delete-row">'. __( 'Delete Row', 'srw-widget' ) .'</span></p>';
$srw_html .= '</div></div>';
}
}
$srw_html .= '</div></div>';
$srw_html .= '<div id="message">'. __( 'Sorry, you reached to the limit of','srw-widget') .' "'.$max_entries.'" '. __( 'maximum entries', 'srw-widget' ) .'.</div>' ;
$srw_html .= '<div class="'.$widget_add_id.'" style="display:none;">' . __('Add New Platform', 'srw-widget') . '</div>';
?>
<script>
jQuery(document).ready(function(e) {
jQuery.each(jQuery(".<?php echo $widget_add_id; ?>-input-containers #entries").children(), function(){
if(jQuery(this).find('input').val() != ''){
jQuery(this).show();
}
});
jQuery(".<?php echo $widget_add_id; ?>" ).bind('click', function(e) {
var rows = 0;
jQuery.each(jQuery(".<?php echo $widget_add_id; ?>-input-containers #entries").children(), function(){
if(jQuery(this).find('input').val() == ''){
jQuery(this).find(".entry-title").addClass("active");
jQuery(this).find(".entry-desc").slideDown();
jQuery(this).find('input').first().val('0');
jQuery(this).show();
return false;
}
else{
rows++;
jQuery(this).show();
jQuery(this).find(".entry-title").removeClass("active");
jQuery(this).find(".entry-desc").slideUp();
}
});
if(rows == '<?php echo $max_entries;?>')
{
jQuery("#rew_container #message").show();
}
});
jQuery(".delete-row" ).bind('click', function(e) {
var count = 1;
var current = jQuery(this).closest('.entrys').attr('id');
jQuery.each(jQuery("#entries #"+current+" .entry-desc").children(), function(){
jQuery(this).val('');
});
jQuery.each(jQuery("#entries #"+current+" .entry-desc p").children(), function(){
jQuery(this).val('');
});
jQuery('#entries #'+current+" .entry-title").removeClass('active');
jQuery('#entries #'+current+" .entry-desc").hide();
jQuery('#entries #'+current).remove();
jQuery.each(jQuery(".<?php echo $widget_add_id; ?>-input-containers #entries").children(), function(){
if(jQuery(this).find('input').val() != ''){
jQuery(this).find('input').first().val(count);
}
count++;
});
});
});
</script>
<style>
.cf:before, .cf:after { content: ""; display: table; }
.cf:after { clear: both; }
.cf { zoom: 1; }
.clear { clear: both; }
.clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
.clearfix { display: inline-block; }
* html .clearfix { height: 1%; }
.clearfix { display: block;}
#rew_container input,select,textarea{ float: right;width: 60%;}
#rew_container label{width:40%;}
<?php echo '.'.$widget_add_id; ?>{
background: #ccc none repeat scroll 0 0;font-weight: bold;margin: 20px 0px 9px;padding: 6px;text-align: center;display:block !important; cursor:pointer;
}
.desc{height:55px;}
#entries{ padding:10px 0 0;}
#entries .entrys{ padding:0; border:1px solid #e5e5e5; margin:10px 0 0; clear:both;}
#entries .entrys:first-child{ margin:0;}
#entries .delete-row{margin-top:20px;float:right;text-decoration: underline;color:red;}
#entries .entry-title{ display:block; font-size:14px; line-height:18px; font-weight:600; background:#f1f1f1; padding:7px 5px; position:relative;}
#entries .entry-title:after{ content: '\f140'; font: 400 20px/1 dashicons; position:absolute; right:10px; top:6px; color:#a0a5aa;}
#entries .entry-title.active:after{ content: '\f142';}
#entries .entry-desc{ display:none; padding:0 10px 10px; border-top:1px solid #e5e5e5;}
#rew_container #entries p.last label{ white-space: pre-line; float:left; width:39%;}
#message{padding:6px;display:none;color:red;font-weight:bold;}
</style>
<div id="rew_container">
<?php echo $srw_html;?>
</div>
<?php
}
I'm pretty new to php and wordpress so any help would be appreciated.
Please try the below code to create a repeater field in the widget.
dd_action( 'widgets_init', 'services_widget' );
function services_widget() {
register_widget( 'services_widget' );
}
class services_widget extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'services_widget',
'description' => 'Add a service description.'
);
$control_ops = array( 'width' => 400, 'height' => 350 );
parent::__construct( 'services_widget', 'Services', $widget_ops, $control_ops );
}
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
echo $args['before_widget'];
if ( ! empty( $title ) ) {
echo $args['before_title'] . $title . $args['after_title'];
}
if( have_rows('service', 'widget_' . $args['widget_id']) ):
echo '<ul>';
while ( have_rows('service', 'widget_' . $args['widget_id']) ) : the_row();
echo '<li class="service one-half">';
$title = get_sub_field( 'title', 'widget_' . $args['widget_id'] );
$body = get_sub_field( 'body', 'widget_' . $args['widget_id']);
$button = get_sub_field( 'button', 'widget_' . $args['widget_id'] );
$button_link = get_sub_field( 'button_link', 'widget_' . $args['widget_id'] );
if( $title ) {
echo '<h4>' . $title . '</h4>';
}
if( $body ) {
echo '<p>' . $body . '</p>';
}
if( $body ) {
echo '<a class="more" href="' . $button_link . '">' .$button . '</a>';
}
echo '</li><div class="clearfix"></div></ul>';
endwhile;
endif;
echo $args['after_widget'];
}
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
$filter = isset( $instance['filter'] ) ? $instance['filter'] : 0;
$title = sanitize_text_field( $instance['title'] );
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox"<?php checked( $filter ); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
if ( current_user_can( 'unfiltered_html' ) ) {
$instance['text'] = $new_instance['text'];
} else {
$instance['text'] = wp_kses_post( $new_instance['text'] );
}
$instance['filter'] = ! empty( $new_instance['filter'] );
return $instance;
}
}

How create list tags in a page with image and count post

I created a list of categories in a page. The code is as follows:
<?php
$args = array(
'orderby' => 'name',
'parent' => 0
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
echo '<div style="margin:0 0 10px 10px; border: 1px solid #888; float: left; padding:1px; text-align:center;"><img src="https://arsipkoran.ga/img/logo/koran-thumb/thumb-' . $category->cat_name . '.png" alt="' . $category->cat_name . '" style="width:180px;height:30px;" /><br/>' . $category->name . '<br/> (' . $category->category_count . ' arsip)</div>';
}
?>
The results are as successful as the following links: https://pustakakoran.com/direktori-e-koran/
Then I try to apply to the tag, the code as follows:
<?php
$args = array(
'orderby' => 'name',
'parent' => 0
);
$tags = get_the_tags( $args );
foreach ( $tags as $tag ) {
echo '<div style="margin:0 0 10px 10px; border: 1px solid #888; float: left; padding:1px; text-align:center;"><img src="https://arsipkoran.ga/img/logo/koran-thumb/thumb-' . $tag->name . '.png" alt="' . $tag->name . '" style="width:180px;height:30px;" /><br/>' . $tag->name . '<br/> (' . $tag->tag_count . ' kitab)</div>';
}
?>
But the result can not. Can anyone help me, which part of the code should be fixed.
Use get_tags() and not get_the_tags().
which part of the code should be fixed
(1) Replace this:
$tags = get_the_tags( $args );
..with this:
$tags = get_tags( $args );
(2) Replace this:
$tag->tag_count
..with this:
$tag->count

post thumbnail "jump" to the header

I'm writing a plugin to display recent posts, however, can't figure out why the thumbnail is not inside the div and "jump" to the header of the page.
This is the code from the plugin:
$my_query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 5
));
if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post();
$html .="<div class=\"My-container\">";
$html .="<div class=\"My-item\">" . the_post_thumbnail('thumbnail', array('class' => 'My-postImg')) . "</div>";
$html .="<div class=\"My-item-1\">";
$html .= "<p>" . the_category(', ') . " | " . the_time('M. d') . "</p>";
$html .= "<h2>" . get_the_title() . " </h2>";
$html .= "<p>" . the_category(', ') . "</p>";
$html .= "Read more";
$html .="</div>";
endwhile; endif;
$content .= $html;;
return $content;
another question: I try to display the recent posts at the end of the post. Therefore I have to return the $content after I add it to the $html. Is there cleaner / more efficient way to do this?
Thanks
thanks for your help. Here's the CSS. Just before, here's the thing: if I put for example just text or , etc. then it will display correctly inside the . Only when it comes to the thumbnail it "jumps".
The .My-container is just a standard flex box
#charset "utf-8";
/* CSS Document */
.My-container {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row nowrap;
flex-direction: row;
flex-wrap: nowrap;
}
.My-item {
min-width: 300px;
min-height: 300px;
background-color: orange;
display: block;
}
.My-item-1 {
width: 200px;
height: 100px;
background-color: green;
}

Wordpress Author Query

I've changed my approach and edited the get_related_author fucntion, but its only bringing in 1 post can someone see where I'm going wrong?
function get_related_author_posts() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID,
'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
foreach ( $authors_posts as $authors_post ) {
$output = '<div class="listio"><ul><li> <div class="author-post">';
$output .= '<div style="background: url(<?php echo $src[0]; ?> ) !important;
width: 80px; height: 50px; float: left; margin-right: 13px;
background-size: 80px 50px!important; background-color: pink;"></div>';
$output .= '<a href="' . get_permalink( $authors_post->ID ) . '">' .
apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) .
'</a>';
$output .= '</div></li></ul></div>';
}
return $output;
}
There you go:
function get_author_related_posts($author_id, $excluded_post){
global $wpdb;
$author_posts = $wpdb->get_results(
"
SELECT post_author, ID
FROM $wpdb->posts
WHERE post_author = '$author_id' and ID != '$excluded_post'
ORDER BY ID DESC
"
);
return $author_posts;
}

How can i post my website content to wordpress and blogger sites

How do i share my website content to wordpress blog and google's blogger like facebook share, twitter share, without any third party tool.
Thanks
Step 1:
Go to your theme’s function.php file and paste below code. This will add sharing button at the bottom of the post
function crunchify_social_sharing_buttons($content) {
if(is_singular() || is_home()){
// Get current page URL
$crunchifyURL = get_permalink();
// Get current page title
$crunchifyTitle = str_replace( ' ', '%20', get_the_title());
// Get Post Thumbnail for pinterest
$crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
$googleURL = 'https://plus.google.com/share?url='.$crunchifyURL;
$bufferURL = 'https://bufferapp.com/add?url='.$crunchifyURL.'&text='.$crunchifyTitle;
// Based on popular demand added Pinterest too
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle;
// Add sharing button at the end of page/page content
$content .= '<div class="crunchify-social">';
$content .= '<h5>SHARE ON</h5> <a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
$content .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
$content .= '<a class="crunchify-link crunchify-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
$content .= '<a class="crunchify-link crunchify-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
$content .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" target="_blank">Pin It</a>';
$content .= '</div>';
return $content;
}else{
// if not a post/page then don't include sharing button
return $content;
}
};
add_filter( 'the_content', 'crunchify_social_sharing_buttons');
Step 2:
Open style.css file of your WordPress theme and put below code for better styling.
.crunchify-link {
padding: 4px 8px 6px 8px;
color: white;
font-size: 12px;
border-radius: 2px;
margin-right: 2px;
cursor: pointer;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
-moz-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
-webkit-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
}
.crunchify-link:hover,.crunchify-link:active {
color: white;
}
.crunchify-twitter {
background: #00aced;
}
.crunchify-twitter:hover,.crunchify-twitter:active {
background: #0084b4;
}
.crunchify-facebook {
background: #3B5997;
}
.crunchify-facebook:hover,.crunchify-facebook:active {
background: #2d4372;
}
.crunchify-googleplus {
background: #D64937;
}
.crunchify-googleplus:hover,.crunchify-googleplus:active {
background: #b53525;
}
.crunchify-buffer {
background: #444;
}
.crunchify-buffer:hover,.crunchify-buffer:active {
background: #222;
}
.crunchify-pinterest {
background: #bd081c;
}
.crunchify-pinterest:hover,.crunchify-pinterest:active {
background: #bd081c;
}
.crunchify-social {
margin: 20px 0px 25px 0px;
-webkit-font-smoothing: antialiased;
font-size: 12px;
}
If you want to show Sharing button at the top of the post then use this code:
function crunchify_social_sharing_buttons($content) {
if(is_singular() || is_home()){
// Get current page URL
$crunchifyURL = get_permalink();
// Get current page title
$crunchifyTitle = str_replace( ' ', '%20', get_the_title());
// Get Post Thumbnail for pinterest
$crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
$googleURL = 'https://plus.google.com/share?url='.$crunchifyURL;
$bufferURL = 'https://bufferapp.com/add?url='.$crunchifyURL.'&text='.$crunchifyTitle;
// Based on popular demand added Pinterest too
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle;
// Add sharing button at the end of page/page content
$variable .= '<div class="crunchify-social">';
$variable .= '<a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
$variable .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
$variable .= '<a class="crunchify-link crunchify-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
$variable .= '<a class="crunchify-link crunchify-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
$variable .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" target="_blank">Pin It</a>';
$variable .= '</div>';
return $variable.$content;
}else{
// if not a post/page then don't include sharing button
return $variable.$content;
}
};
add_filter( 'the_content', 'crunchify_social_sharing_buttons');
Take a look here

Resources