I'm working on a WooCommerce shop, and I want to show the Total Price on the product page, just below the add to cart button. All the codes I found do that based on the original price, not the discounted price. To calculate the discount, I'm using pricing rules and the plugin is "Advanced Dynamic Pricing for WooCommerce".
/* Calculate Subtotal Based on Quantity - WooCommerce Single Product */
add_action( 'woocommerce_after_add_to_cart_button', 'bbloomer_product_price_recalculate' );
function bbloomer_product_price_recalculate() {
global $product;
echo '<div id="subtot" style="display:inline-block;">Total: <span></span></div>';
$price = $product->get_price();
$currency = get_woocommerce_currency_symbol();
wc_enqueue_js( "
$('[name=quantity]').on('input change', function() {
var qty = $(this).val();
var price = '" . esc_js( $price ) . "';
var price_string = (price*qty).toFixed(2);
$('#subtot > span').html('" . esc_js( $currency ) . "'+price_string);
}).change();
" );
}
This code works, but it doesn't take into account the pricing rules.
Thank you!
I tried adding this code I found (Calculate Subtotal Based on Quantity), but it doesn't work with the pricing rules. I tried a few plugins for dynamic pricing, and always I get the original product price multiplied with the quantity. It doesn't take into account the pricing rules.
On my WooCommerce checkout page, I am trying to show a notification before the order review section when the total of the cart equals €0.01
So far, I have placed the following in the functions.php file of my child theme:
add_action('woocommerce_checkout_before_order_review', 'test_funtion');
function test_funtion(){
?>
<p>Notice goes here</p>
<?php
}
How can I modify these lines such that this notice is only shown if the order total equals € 0.01?
You can use WC_Cart::get_cart_contents_total(); - Gets cart total. This is the total of items in the cart, but after discounts. Subtotal is before discounts.
So you get:
function action_woocommerce_checkout_before_order_review () {
// Get cart total
$cart_total = WC()->cart->get_cart_contents_total();
// Compare
if ( $cart_total == 0.01 ) {
echo '<p>' . __( 'My message', 'woocommerce' ) . '</p>';
}
}
add_action( 'woocommerce_checkout_before_order_review', 'action_woocommerce_checkout_before_order_review', 10, 0 );
I use cart Widget as minicart details in top menu. In Mini cart details page display wrong cart subtotal (Product Amount without Discount). but checkout page display correct total amount how to fix it.
if ( WC()->cart->get_cart_contents_count() > 0 ) { echo '<span class="circle" id="mini-cart-details">' . WC()->cart->get_cart_contents_count() . ' items - '.WC()->cart->get_cart_total().'</span>'; } else { echo '<span class="circle" id="mini-cart-details"> items - '.WC()->cart->get_cart_total().'</span>'; }
I have the same issue with taxes. $order->get_formatted_order_total() returns incorrect and different value than $order->get_total().
I m using opencart 2.x for development and i am really stuck in cart and invoices. My scenario is that,
I want to show VAT only while sending invoice to the customer and VAT shall not be visible in Cart but total in cart shall be including VAT.
What I want is to not display the tax in cart and if I disable it in the admin screen it does not count up correctly and is not appearinf in Invoice as well. So it must be hidden in the code.
Presentation in Cart shall be
Subtotal // This subtotal shall inclusive of VAT here
Shipping
Total // This total shall inclusive of VAT here
Presentation in Invoice shall be
Subtotal // This subtotal shall exclusive of VAT here
Shipping
VAT(1%) // VAT is shown here
Total // This total shall inclusive of VAT here
Currently, i have presenation in cart and invoice same as of invoice shown above.
I have enabled Taxes in Extensions > Order Totals but i do not know how to modify the total array in opencart.
You need to replace code :--
catalog/controller/checkout/cart.php
Find Below code :--
foreach ($results as $result)
{
if ($this->config->get($result['code'] . '_status'))
{
$this->load->model('total/' . $result['code']);
$this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
}
}
Replace with This Code :--
foreach ($results as $result)
{
if ($this->config->get($result['code'] . '_status'))
{
$this->load->model('total/' . $result['code']);
if($result['code'] != "tax")
{
$this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
}
}
}
I have a pretty weird issue, I hope someone can help me with this.
Here are the major config settings that influence my problem:
Catalog prices in admin panel are shown including tax
Catalog prices in frontend are shown including tax
Items in shopping cart are shown excluding tax (so it's displayed separately near the subtotal).
Everything is working fine so far. The problem comes in a custom ajax mini cart module. I grab the collection of items from the cart, but, since I'm getting the price from the shopping cart item, I get it without tax.
Here is some code to exemplify what I mean. I will assume a 20% tax and a product that has the admin price (including tax) set to 120$, an option that costs 60$ (also including tax). Excluding tax these would be 100$ and 50$. I want to get the price + option + tax => 180$
$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllVisibleItems();
foreach ($items as $item) {
echo $item->getPrice(); // 150$ - price excluding tax
echo $item->getPriceInclTax(); // 150$ - price excluding tax
echo $item->getProduct()->getPrice(); // 120$ price including tax, BUT without the customer selected options.
}
PS: The custom option I am talking about is user selected, for example an install checkbox that adds +50$ to the price of the product.
- Get products id, name, price, quantity, etc. present in your cart.
- Get number of items in cart and total quantity in cart.
- Get base total price and grand total price of items in cart.
Get all items information in cart
// $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($items as $item) {
echo 'ID: '.$item->getProductId().'<br />';
echo 'Name: '.$item->getName().'<br />';
echo 'Sku: '.$item->getSku().'<br />';
echo 'Quantity: '.$item->getQty().'<br />';
echo 'Price: '.$item->getPrice().'<br />';
echo "<br />";
}
Get total items and total quantity in cart
$totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
$totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
Get subtotal and grand total price of cart
$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();
Have you tried:
$product->getFinalPrice();
// or this?
$product->getPriceModel()->getFinalPrice($qty, $product);
what is the ouput of $item->getOptions()?
Have you tried $item->getData('price')?
How do you apply your custom options? What is the ouput of $item->debug()? Maybe you can find what you need there.
Regards
Simon
I didn't find a solution to my exact problem, but I changed the settings to mimic this exact functionality, and the problem I encountered was no longer there.
First of all, I removed all the taxes on the site, and told magento all the prices are excluding tax (even though they are including tax).
The tax reduction is now made through a promotion applied on a custom group, so for
$tax = 20; // percent
I add a reduction of
(1 - (1 / ($tax / 100 + 1)))*100
// for 20% tax => 16.6667% reduction
// for 24% tax => 19.3548% reduction
with 4 decimals (that's as much as magento accepts). It may have an error of 1 cent from time to time - so if this is not an issue, go for it!
Now the prices all over the website will be shown exactly for the product (because the promotion is applied per cart, not per product).
You can try This :
$grandTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
echo $text .= $this->__(' Total: %s', $this->helper('core')->formatPrice($grandTotal, false));
show the quantity of a cart in my header
if ($parentBlock = $this->getParentBlock()) {
$count = $this->helper('checkout/cart')->getSummaryCount();
if( $count == 1 ) {
echo $text = $this->__('My Cart (%s item)', $count);
} elseif( $count > 0 ) {
echo $text = $this->__('My Cart (%s items)', $count);
} else {
echo $text = $this->__('My Cart (0 items)');
}
}
show the total price of a cart in my header
$grandTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
echo $text .= $this->__(' Total: %s', $this->helper('core')->formatPrice($grandTotal, false));