Unfortunately woocommerce doesn't display its invoices the way it is supposed to be in Germany. Right now it's
product name - quantity - price
I need the invoice mail template to say
product name - *single price* - *tax rate (e.g. 19%)* - quantity - price
I know I have to put this into
/my-theme/woocommerce/emails/email-order-items.php
somewhere here:
<?php
/**
* Email Order Items
*
* #author WooThemes
* #package WooCommerce/Templates/Emails
* #version 2.0.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $woocommerce;
foreach ($items as $item) :
// Get/prep product data
$_product = $order->get_product_from_item( $item );
$item_meta = new WC_Order_Item_Meta( $item['item_meta'] );
$image = ($show_image) ? '<img src="'. current(wp_get_attachment_image_src( get_post_thumbnail_id( $_product->id ), 'thumbnail')) .'" alt="Product Image" height="'.$image_size[1].'" width="'.$image_size[0].'" style="vertical-align:middle; margin-right: 10px;" />' : '';
?>
<tr>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee; word-wrap:break-word;"><?php
// Show title/image etc
echo apply_filters( 'woocommerce_order_product_image', $image, $_product, $show_image);
// Product name
echo apply_filters( 'woocommerce_order_product_title', $item['name'], $_product );
// SKU
echo ($show_sku && $_product->get_sku()) ? ' (#' . $_product->get_sku() . ')' : '';
// File URLs
if ( $show_download_links && $_product->exists() && $_product->is_downloadable() ) {
$download_file_urls = $order->get_downloadable_file_urls( $item['product_id'], $item['variation_id'], $item );
$i = 0;
foreach ( $download_file_urls as $file_url => $download_file_url ) {
echo '<br/><small>';
$filename = woocommerce_get_filename_from_url( $file_url );
if ( count( $download_file_urls ) > 1 ) {
echo sprintf( __('Download %d:', 'woocommerce' ), $i + 1 );
} elseif ( $i == 0 )
echo __( 'Download:', 'woocommerce' );
echo ' ' . $filename . '</small>';
$i++;
}
}
// Variation
echo ($item_meta->meta) ? '<br/><small>' . nl2br( $item_meta->display( true, true ) ) . '</small>' : '';
?></td>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo $item['qty'] ;?></td>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo $order->get_formatted_line_subtotal( $item ); ?></td>
</tr>
<?php if ($show_purchase_note && $purchase_note = get_post_meta( $_product->id, '_purchase_note', true)) : ?>
<tr>
<td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo apply_filters('the_content', $purchase_note); ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
Can you change the output to be like this
product name - *single price* - *tax rate (e.g. 19%)* - quantity - price
Thanks for your help!
You can display single item price exclusive of tax by adding the following line:
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo $order->get_item_total( $item, false ); ?></td>
just above this line:
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php echo $item['qty'] ;?></td>
This, however, will add additional column so you must add this column to other rows as well (table head and totals). To do so, open each of email templates that include this table and add this line:
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Price (excl. tax)', 'woocommerce' ); ?></th>
just below this line:
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Product', 'woocommerce' ); ?></th>
Also change this line:
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
into this:
<th scope="row" colspan="3" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
Now, displaying order/item tax this way would be hard as WooCommerce orders may have multiple different taxes applied. You may, however, hardcode it into the template.
You may wish to give WooCommerce PDF Invoice plugin a try - it has an option to display prices/subtotals exclusive of tax, then tax rows, then total inclusive of tax.
Probably a bit old but: Just change the tax name in woocommerce->settings->tax from Mwst. to Mwst. (19%) and so on
Related
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;
}
}
When I paste code in the function.php, my website stop working and an error shows up "The site is experiencing technical difficulties"
/**
* Adding Shortcode 'box'
*/
function boxShow($atts, $content = null ){
//default values
$option = shortcode_atts( array(
'type' => '',
), $atts );
ob_start();
$class = $option[ 'type' ] ? str_replace( '"', '', $option[ 'type' ] ) : 'normal';
//HTML goes here
?>
<div class="box <?php echo $class; ?>"><?php echo $content; ?></div>
<?php
$output = ob_get_clean();
return $output;
}
add_shortcode( 'box', 'boxShow' );
and CSS Code
.shadow , .success , .info{
padding: 12px 12px;
background-color: #fafafa;
border: 1px solid black;
margin-bottom:8px;
I want to create a shortcode in an existing Wordpress/Woocommerce plugin. Where do I put the code to create the shortcode?
The plugin displays a table with all the available variations on any given variable product on the product page.
The table reacts to what the customer selects on the attributes form.
I want to make a shortcode so that I can show this in a tab on the product page instead of before the add to cart button as is now. Where should I put the code for the shortcode?
<?php
/*
Plugin Name: Variations On Product Page
Description: Display all the available variations on the product page
Version: 1.2
*/
define( 'VARIATIONS_ON_PRODUCT_VER', '1.2' );
define( 'VARIATIONS_ON_PRODUCT_PATH', plugin_dir_path( __FILE__ ) );
define( 'VARIATIONS_ON_PRODUCT_URL', plugin_dir_url( __FILE__ ) );
require_once 'settings.php';
if ( ! isset( Variations_Product_Settings::getSettings()['enabled'] ) ) {
return;
}
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_script( 'variations-on-product', VARIATIONS_ON_PRODUCT_URL . 'assets/variations-on-product.js', [ 'jquery' ], VARIATIONS_ON_PRODUCT_VER );
wp_localize_script( 'variations-on-product', 'variations_on_product_settings', apply_filters( 'variations_on_product_js_settings', [
'options' => Variations_Product_Settings::getSettings(),
] ) );
wp_enqueue_style( 'variations-on-product', VARIATIONS_ON_PRODUCT_URL . 'assets/variations-on-product.css', [], VARIATIONS_ON_PRODUCT_VER );
} );
add_action( 'woocommerce_before_add_to_cart_button', function () {
global $product;
/* #var WC_Product $product */
if( !$product->is_type('variable') ) return;
?>
<style>
#product-variations .attachment-woocommerce_thumbnail {
max-width: 100px;
}
table#product-variations .custom_form .quantity {
float: none !important;
width: 100% !important;
margin-right: 0 !important;
}
table#product-variations .custom_form .input-text.qty {
width: 100% !important;
box-sizing: border-box;
}
table#product-variations .custom_form button.button.alt {
width: 100%;
}
table#product-variations .custom_form p.stock {
margin-bottom: 3px !important;
text-align: center;
font-size: 14px
}
</style>
<table id="product-variations">
<thead>
<tr>
<?php if( !Variations_Product_Settings::getSettings()['hide_thumbnail'] ): ?>
<td>Image</td>
<?php endif; ?>
<td>Title</td>
<td>Price</td>
<td>*</td>
</tr>
</thead>
<tbody></tbody>
</table>
<?=Variations_Product_Settings::getSettings()['load_more_text'] ?: 'Load more'?>
<?php
} );
add_filter( 'woocommerce_available_variation', function ( $default, $product, $variation ) {
/* #var WC_Product_Variation $variation */
ob_start();
?>
<tr>
<?php if( !Variations_Product_Settings::getSettings()['hide_thumbnail'] ): ?>
<td>
<?= $variation->get_image() ?>
</td>
<?php endif; ?>
<td>
<?= $variation->get_name() ?>
<p>
<small><?= $variation->get_sku() ?></small>
</p>
</td>
<td>
<?= $variation->get_price_html() ?>
</td>
<td>
<?php if ( $variation->is_in_stock() ) : ?>
<form class="custom_form" action="<?php echo esc_url( get_permalink() ); ?>" method="post" enctype='multipart/form-data'>
<?php
if( !Variations_Product_Settings::getSettings()['hide_stock_status'] ) {
if ( $variation->managing_stock() ) {
echo wc_get_stock_html( $variation );
}
}
?>
<?php
if( !Variations_Product_Settings::getSettings()['hide_qty'] ) {
woocommerce_quantity_input( [
'min_value' => apply_filters( 'woocommerce_quantity_input_min', $variation->get_min_purchase_quantity(), $variation ),
'max_value' => apply_filters( 'woocommerce_quantity_input_max', $variation->get_max_purchase_quantity(), $variation ),
'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : $variation->get_min_purchase_quantity(),
] );
}
?>
<button type="submit" name="add-to-cart" value="<?php echo esc_attr( $variation->get_id() ); ?>" class=" button alt"><?php echo esc_html( $variation->single_add_to_cart_text() ); ?></button>
</form>
<?php endif; ?>
</td>
</tr>
<?php
$default['c_template'] = apply_filters('vop_variation_template', ob_get_clean(), $variation);
return $default;
}, 10, 3 );
// Hide add to cart on product
if ( isset( Variations_Product_Settings::getSettings()['hide_product_addtocart'] ) ) {
add_action( 'woocommerce_before_add_to_cart_button', function () {
?>
<style>
.single_variation_wrap {
display: none !important;
}
</style>
<?php
} );
}
I tried to add the following code but did not work.
<?php
/*
Plugin Name: Variations On Product Page
Description: Display all the available variations on the product page
Version: 1.2
*/
add_shortcode( 'minkod', 'mitt_lilla_shortcode_handler' );
define( 'VARIATIONS_ON_PRODUCT_VER', '1.2' );
define( 'VARIATIONS_ON_PRODUCT_PATH', plugin_dir_path( __FILE__ ) );
define( 'VARIATIONS_ON_PRODUCT_URL', plugin_dir_url( __FILE__ ) );
I added the function:
function mitt_lilla_shortcode_handler () {
$myshortcode ='
add_action( 'woocommerce_before_add_to_cart_button', function () {
global $product;
/* #var WC_Product $product */
if( !$product->is_type('variable') ) return;
?>
And in the end:
> <style>
> .single_variation_wrap {
> display: none !important;
> } </style> <?php } ); ';} return $myshortcode; }
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
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.