Show prices including tax on product page - wordpress

I am using woocoommerce V3.0.9, and have tax settings enabled. I set Prices entered with tax as Yes, I will enter prices inclusive of tax and Display prices in the shop as Including Tax and Additional tax classes as Reduced Rate Zero Rate.
Also, while adding product i added product prices including tax. But on product detail page the prices are showing without tax. For example i added product price 135.90 while adding product including Tax and on product detail page its showing me price 123.55 excluding Tax but it should show 135.90 as i have set the setting to show prices including tax.
On checkout page, i am getting product price 123.55 + 12.35 Tax = 135.90 as product total price which is working fine.
But i want to show the actual price including tax on product detail page so that customer knows the original price before adding product to cart.
Can anyone help me how i can get this working.
Thanks in advance.

Before check that your WooCommerce Tax general settings match with your needs.
As suggested, you need to copy from woocommerce the templates folder inside your active child theme or theme. Then rename it woocommerce. In this woocommerce templates folder you will find inside single-product subfolder the price.php template to edit related to pricing display in single product pages.
In price.php just after:
global $product;
Replace the code with:
?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php
$simple_product_price = $product->get_price_html(); // price without VAT
$simple_product_total = $product->get_price_including_tax(); // price with included VAT
$simple_product_vat = $simple_product_total - $simple_product_price; // VAT price amount
?>
<p class="price"><?php echo $simple_product_price; /* without VAT */ ?></p> (formatted)
<p class="price-vat"><?php echo $simple_product_vat; /* VAT */ ?></p>
<p class="price-and-vat"><?php echo $simple_product_total; /* With VAT */ ?></p>
<meta itemprop="price" content="<?php echo esc_attr( $product->get_price() ); ?>" />
<meta itemprop="priceCurrency" content="<?php echo esc_attr( get_woocommerce_currency() ); ?>" />
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />
</div>
Because the additional prices are unformatted, you may need to mix some other elements with this additionals prices using some woocommerce php functions like:
get_price_suffix( ) // Get the suffix to display after prices > 0.
$currency = esc_attr( get_woocommerce_currency( ) ) // Get the currency code.
get_woocommerce_currency_symbol( $currency ) // Get the currency symbol.
get_tax_class( ) // Returns the tax class.
get_tax_status( ) // Returns the tax status.
Woocommerce Reference Link: https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html

Related

How to display product price on custom meta filed woocommerce?

I want to display product price on single page custom field. That filed is only readable filed users cant option to edit that price. Also on variable product page when product variations change according to that price also need to change. I have added below code for display the the custom field on single product page.
add_action('woocommerce_before_add_to_cart_button', 'my_custom_checkout_field');
function my_custom_checkout_field() {
// global $product;
echo "test";
echo '<div id="my_custom_checkout_field">';
echo ' <input type="text" name="my_field_name">';
echo '</div>';
}
I want to add variations product price on that filed.
To get Product price without woocommerce hook
define product as global
global $product;
and then get product price
$product->get_price();
add_action('woocommerce_before_add_to_cart_button', 'my_custom_checkout_field');
function my_custom_checkout_field() {
global $product;
$price = $product->get_price();
echo "test";
echo '<div id="my_custom_checkout_field">';
echo ' <input type="text" name="my_field_name" value=".$price.">';
echo '</div>';
}

Woocommerce - Hide price when empty

I use woocommerce.
In my product page, I have changed the code in price.php to show both price inclusive and exclusive taxes. But for some products, there is no price and they have to contact us to get the price. So when the price is empty, I don't want to show the text with the prices.
I have combined some code that I found, with the code I already had, but it doesn't really work, I keep getting the "excl. BTW €0,00 incl. BTW" text, even when the price of the product is empty.
<p class="price"><?php if( !empty(woocommerce_price ($product-> get_price_excluding_tax ()))) { echo $product->get_price_html() . ' excl. BTW<br />' . wc_price( wc_get_price_including_tax( $product ) ) . ' incl. BTW'; } ?></p>
Thanks in advance!

Show discount price on changing product quantity - Woocommerce Dynamic Pricing plugin

I am using Woocommerce Dynamic Pricing plugin and facing issue to show discounted price on product detail page.
I have 3 user roles and set pricing rules with minimum and maximum product quantity on fixed price. When I am logged in with that specific role (stockist), it's not showing me the discount price.
If I add that product to the cart then it shows me discounted price in cart.
Is there a way I can change the price on changing product quantity.
I have pricing rule as:
1) product quantity is in between 4-16 price is $40
2) product quantity is in between 17-50 price is $39
3) product quantity is in between 51 and more price is $35
I found a code but that is not working with dynamic pricing rules:
add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 31 );
function woocommerce_total_product_price() {
global $woocommerce, $product;
// let's setup our divs
echo sprintf('<div id="product_total_price" style="margin-bottom:20px;display:none">%s %s</div>',__('Product Total:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
echo sprintf('<div id="cart_total_price" style="margin-bottom:20px;display:none">%s %s</div>',__('Cart Total:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
?>
<script>
jQuery(function($){
var price = <?php echo $product->get_price(); ?>,
current_cart_total = <?php echo $woocommerce->cart->cart_contents_total; ?>,
currency = '<?php echo get_woocommerce_currency_symbol(); ?>';
$('[name=quantity]').change(function(){
if (!(this.value < 1)) {
var product_total = parseFloat(price * this.value),
cart_total = parseFloat(product_total + current_cart_total);
$('#product_total_price .price').html( currency + product_total.toFixed(2));
$('#cart_total_price .price').html( currency + cart_total.toFixed(2));
}
$('#product_total_price,#cart_total_price').toggle(!(this.value <= 1));
});
});
</script>
<?php
}
Can anyone suggest me a way to do that.
Thanks

WooCommerce-Send Custom Selected Price in Cart

Hello Everyone I have customized the woo-commerce single product page according to my requirement, So now two prices are coming first price is my custom price as per my selection, Second price i have entered from WooCommerce product page(entered from wp-admin dashboard), right now second price is going in cart but i want to pass custom price how can i achieve this please suggest me thank you in advance.
Using ajax I am changing my custom price
Custom Price:
<p class="prices" id="demo" style="margin-left:22%;"></p>
Default Price:
<p class="prices" id="demo" style="margin-left:22%;"><?php echo $product->get_price_html(); ?></p>
Update:
I am using this code
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price');
function add_custom_price( $cart_object ) {
$custom_price = 70; // This will be your custome price
foreach ( $cart_object->cart_contents as $key => $value ) {
$value['data']->price = $custom_price;
}
}
right now 70 is static price instead of this i want to pass paragraph because I am getting my price in paragraph using ajax..
<p class="prices" id="demo" style="margin-left:22%;"></p>
add_action('woocommerce_get_price','change_price_custom', 10, 2);
function change_price_custom($price, $productd){
return $price*2; // do calculation here
}
Try this in theme's function.php

Include the current product category name at the top of the single product page in woocommerce?

Just wanted to ask if anyone here can tell me how to include the current product category name at the top of the single product page in Woocommerce.
I'm going to want to place it above the breadcrumb trail at the top of my product page. I've included a link to an example of what I'm looking for here: http://www.espguitars.com/guitars/signature/kirk.html -
Notice at the top right-hand corner of the page you'll see the current category name, in this case, the category name is Guitars. I realize that the site example I've given is not a wordpress site, but I feel certain there's a way to do this with woocommerce.
If you check the meta.php file in the "templates/single-product" folder of the WooCommerce plugin, you'll see how the WooCommerce plugin displays the product categories of the current product as product meta information.
<?php
...
global $post, $product;
?>
<div class="product_meta">
...
<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', sizeof( get_the_terms( $post->ID, 'product_cat' ) ), 'woocommerce' ) . ' ', '.</span>' ); ?>
...
</div>
Please copy the code to your theme and modify it accordingly.

Resources