I'm building a site in wordpress and when I goto cart this keeps popping up
"(estimated for Australia)" right after TAX then gives the value of the tax on the item/s.
I checked out another question and answer on here for the same thing however they had different code to the code I have. I tried a few different things but can't figure it out.
This is the code when I inspect it on google chrome for the cart.
<tr class="tax-total">
<th>Tax <small>(estimated for Australia)</small></th>
<td data-title="Tax">
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">$</span>109.80</span>
</td>
</tr>
Can someone figure out a filter fix for me?
You can do it by editing WooCommerce cart template file of your theme. I guess that is hardcoded there in cart.php.
Or if you want easier solution, just hide it with CSS.
This code hides "(estimated for {country})" part:
.tax-total th small {display:none!important}
This one hides
.tax-total {display:none!important}
The responsible function for that behavior is wc_cart_totals_order_total_html() … But hopefully you can change that using the following code hooked function:
add_filter( 'woocommerce_cart_totals_order_total_html', 'filtering_cart_totals_order_total_html', 20, 1 );
function filtering_cart_totals_order_total_html( $value ){
$value = '<strong>' . WC()->cart->get_total() . '</strong> ';
// If prices are tax inclusive, show taxes here.
if ( wc_tax_enabled() && WC()->cart->display_prices_including_tax() ) {
$tax_string_array = array();
$cart_tax_totals = WC()->cart->get_tax_totals();
if ( get_option( 'woocommerce_tax_total_display' ) == 'itemized' ) {
foreach ( $cart_tax_totals as $code => $tax ) {
$tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
}
} elseif ( ! empty( $cart_tax_totals ) ) {
$tax_string_array[] = sprintf( '%s %s', wc_price( WC()->cart->get_taxes_total( true, true ) ), WC()->countries->tax_or_vat() );
}
if ( ! empty( $tax_string_array ) ) {
$value .= '<small class="includes_tax">' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) ) . '</small>';
}
}
return $value;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
You will get:
Instead of:
This is an update for Woocommerce 3.2+ slight different, based on this answer: Remove "estimated for {country}" text after tax amount in Woocommerce checkout page
Related
After an update of WooCommerce & WordPress a lot of custom settings was overwritten so I have tried to get back the same functionality as in the older version. (using childtheme so why it went missing in the first place I dont get)
Fixed everything except this. On the billing info at checkout several fields went missing, the default company_name I got working again , for some reason it was deactivated in the theme functions.php. However two custom fields are left for IVA number and Organization number.
So I used Checkout Manager for WooCommerce to add custom fields to the billing info.
It works on the check out page and the info end up on the order. But it doesn't show up on the thank you page and more importantly it doesn't show up on the email to customer.
Tried adding this to themes functions.php but no luck.
add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
$fields['billing_wooccm13'] = array(
'label' => __( 'Moms/IVA' ),
'value' => get_post_meta( $order->id, 'billing_wooccm13', true ),
);
return $fields;
}
And also tried this:
add_action('woocommerce_email_customer_details','add_custom_checkout_field_to_emails_notifications', 25, 4 );
function add_custom_checkout_field_to_emails_notifications( $order, $sent_to_admin, $plain_text, $email ) {
$output = '';
$billing_field_testing = get_post_meta( $order->id, 'billing_wooccm13', true );
if ( !empty($billing_wooccm13) )
$output .= '<div><strong>' . __( "Some text:", "woocommerce" ) . '</strong> <span class="text">' . $billing_wooccm13 . '</span></div>';
echo $output;
}
Any ideas how to go about this?
Since WoooCommerce 3 $order->id is replaced by $order->get_id()… Also there are some other ways.
Be sure that the meta key for your custom field is billing_wooccm13 (as it could be instead starting with an underscore like _billing_wooccm13).
Try the following:
add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
if ( $value = $order->get_meta( 'billing_wooccm13' ) ) {
$fields['billing_wooccm13'] = array(
'label' => __( 'Moms/IVA' ),
'value' => $value,
);
}
return $fields;
}
Code goes in functions.php file of the active child theme (or active theme). It should work.
Or this too:
add_action('woocommerce_email_customer_details','add_custom_checkout_field_to_emails_notifications', 25, 4 );
function add_custom_checkout_field_to_emails_notifications( $order, $sent_to_admin, $plain_text, $email ) {
if ( $value = $order->get_meta( 'billing_wooccm13' ) ) {
echo '<div><strong>' . __( "Some text:", "woocommerce" ) . '</strong> <span class="text">' . $value . '</span></div>';
}
}
Code goes in functions.php file of the active child theme (or active theme). It should work.
Thank you so much LoicTheAztec.
Both solutions worked but with the first one the text ended up to high up, before invoice address. The second one ended up below , unfortunately with some blank lines before but no biggie. Assume I have to use an email-template to remove those lines. The code I ended up with:
add_action('woocommerce_email_customer_details','add_custom_checkout_field_to_emails_notifications', 25, 4 );
function add_custom_checkout_field_to_emails_notifications( $order, $sent_to_admin, $plain_text, $email ) {
if ( $value = $order->get_meta( '_billing_wooccm11' ) ) {
echo '<div><strong>' . __( "Ert organisationsnummer", "woocommerce" ) . '</strong> <span class="text">' . $value . '</span></div>';
if ( $value = $order->get_meta( '_billing_wooccm13' ) ) {
echo '<div><strong>' . __( "Ert Moms/IVA:", "woocommerce" ) . '</strong> <span class="text">' . $value . '</span></div>';
}
}
}
Been trying to find something about this, but the solutions I found so far here do not work.
I need, in the single product page, to display the add to cart button like this:
ADD TO CART - JUST $PRICE
It needs to be done from the functions.php file in the child theme.
Thanks a lot!
To handle the display of the product price in add-to-cart button for all product prices on shop, other archives pages and single product pages, without any need of overriding templates, using dedicated Woocommerce filter hooks:
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Shop and other archives pages
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Single product pages
function custom_add_to_cart_price( $button_text, $product ) {
// Variable products
if( $product->is_type('variable') ) {
// shop and archives
if( ! is_product() ){
$product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $product->get_variation_price() ) ) );
return $button_text . ' - From ' . strip_tags( $product_price );
}
// Single product pages
else {
return $button_text;
}
}
// All other product types
else {
$product_price = wc_price( wc_get_price_to_display( $product ) );
return $button_text . ' - Just ' . strip_tags( $product_price );
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
On shop page:
On single product pages:
I would suggest you override the WooCommerce template from the child theme, the file name is add-to-cart.php and can be found at woocommerce > loop.
At the bottom add the following code, it will be displayed only in product single.
if (is_single()) {
echo sprintf(
'<span>%s %s</span>',
esc_attr__('JUST', 'woocommerce'),
esc_attr($product->price)
);
}
Edit your woocommerce/loop/add-to-cart.php template file like this:
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $product;
echo apply_filters( 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
sprintf( '<a href="%s" data-quantity="%s" class="%s" %s>ADD TO CART - JUST %s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
$product->get_price()
),
$product, $args );
For the single product pages do basically the same in:
woocommerce/single-product/add-to-cart/simple.php
And any other template you use in the add-to-cart directory.
Note: Don't edit the plugin file itself but override the template in your (child) theme so it won't be overwritten when the plugin gets updated.
Been trying to find something about this, but the solutions I found so far here do not work.
I need, in the single product page, to display the add to cart button like this:
ADD TO CART - JUST $PRICE
It needs to be done from the functions.php file in the child theme.
Thanks a lot!
To handle the display of the product price in add-to-cart button for all product prices on shop, other archives pages and single product pages, without any need of overriding templates, using dedicated Woocommerce filter hooks:
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Shop and other archives pages
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Single product pages
function custom_add_to_cart_price( $button_text, $product ) {
// Variable products
if( $product->is_type('variable') ) {
// shop and archives
if( ! is_product() ){
$product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $product->get_variation_price() ) ) );
return $button_text . ' - From ' . strip_tags( $product_price );
}
// Single product pages
else {
return $button_text;
}
}
// All other product types
else {
$product_price = wc_price( wc_get_price_to_display( $product ) );
return $button_text . ' - Just ' . strip_tags( $product_price );
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
On shop page:
On single product pages:
I would suggest you override the WooCommerce template from the child theme, the file name is add-to-cart.php and can be found at woocommerce > loop.
At the bottom add the following code, it will be displayed only in product single.
if (is_single()) {
echo sprintf(
'<span>%s %s</span>',
esc_attr__('JUST', 'woocommerce'),
esc_attr($product->price)
);
}
Edit your woocommerce/loop/add-to-cart.php template file like this:
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $product;
echo apply_filters( 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
sprintf( '<a href="%s" data-quantity="%s" class="%s" %s>ADD TO CART - JUST %s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
$product->get_price()
),
$product, $args );
For the single product pages do basically the same in:
woocommerce/single-product/add-to-cart/simple.php
And any other template you use in the add-to-cart directory.
Note: Don't edit the plugin file itself but override the template in your (child) theme so it won't be overwritten when the plugin gets updated.
I try to do a quite simple thing but for me i don´t get it to work.
This is from the wc-cart-functions.php
if ( ! empty( $tax_string_array ) ) {
$taxable_address = WC()->customer->get_taxable_address();
$estimated_text = WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping()
? sprintf( ' ' . __( 'estimated for %s', 'woocommerce' ), WC()->countries->estimated_for_prefix( $taxable_address[0] ) . WC()->countries->countries[ $taxable_address[0] ] )
: '';
$value .= '<small class="includes_tax">' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) . $estimated_text ) . '</small>';
}
}
echo apply_filters( 'woocommerce_cart_totals_order_total_html', $value );
}
The $value should be different if any $fee is applied.
But I only get 0.00 € Value from $fee Variable if I check for.
Could someone please help me with simply apply the Value of the FEE in a Variable and check in a simple if clause like:
if fee is applied ---> 1
else ---> 2
How can I do it?
As you can see you can use the woocommerce_cart_totals_order_total_html filter hook located in that wc-cart-functions.php core code, to alter the output of grand cart total:
add_filter( 'woocommerce_cart_totals_order_total_html', 'custom_cart_totals_order_total_html', 10, 1 );
function custom_cart_totals_order_total_html( $value ) {
// Get the fee cart amount
$fees_total = WC()->cart->fee_total;
// HERE is the condition
if( ! empty($fees_total) && $fees_total != 0 ){
// Change/customize HERE $value (just for test)
$value .= " <small>($fees_total)<small>";
}
// Always return $value
return $value;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.
Never overide core files, as this is something prohibited, dangerous and not convenient for many reasons
You will need to customize the code in the condition for $value
actions and filters. On my WooCommerce site I get the following message when I remove a product from the shopping cart:
"<product name>" removed. Undo?
Looking over WooCommerce source code I have found a conditional statement in class-wc-form-header.php as part of the function update_cart_action():
$removed_notice .= ' ' . __( 'Undo?', 'woocommerce' ) . '';
But I can't find the way to use it for eliminate this notice. I have try css solutions but it didn't work:
PS: that may not be the code snippet that is bothering me, but its the only one I have found that seems to make sense.
How can I remove this bothering notice?
Thanks.
You can do that in different ways:
1. Overriding the notices.php template:
You have first (if not done yet) to copy woocommerce templates folder inside your active child theme or theme, then rename it woocommerce. Then open/edit notices/notices.php and try to replace the code:
<?php
/**
* Show messages
* ... Blabla ... / ... blabla ...
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! $messages ){
return;
}
?>
<?php foreach ( $messages as $message ) : // Change your template code from here
if ( strpos( $message, 'removed' ) === false ) : ?>
<div class="woocommerce-info"><?php echo wp_kses_post( $message ); ?></div>
<?php endif;
endforeach; ?>
2. Using hooks:
function remove_added_to_cart_notice()
{
$notices = WC()->session->get('wc_notices', array());
foreach( $notices['notices'] as $key => &$notice){
if( strpos( $notice, 'removed' ) !== false){
$added_to_cart_key = $key;
break;
}
}
unset( $notices['notices'][$added_to_cart_key] );
WC()->session->set('wc_notices', $notices);
}
add_action('woocommerce_before_single_product','remove_added_to_cart_notice',1);
add_action('woocommerce_shortcode_before_product_cat_loop','remove_added_to_cart_notice',1);
add_action('woocommerce_before_shop_loop','remove_added_to_cart_notice',1);
3. Using CSS (with something like):
.woocommerce-cart .woocommerce-message {
display: none !important;
}
References:
Wordpress - Woocommerece remove "Added to Cart" message
New wc-notice-functions.php on github
I had to change this to get it to work. Specifically, the array field is singular notice or at least it is now.
$notices = WC()->session->get('wc_notices', array());
foreach( $notices['notice'] as $key => &$notice){
if( strpos( $notice, 'whilst' ) !== false){
$BadNotice_key = $key;
unset( $notices['notice'][$BadNotice_key] );
WC()->session->set('wc_notices', $notices);
break;
}
}
Just an update regarding Overriding the notices.php template:
<?php foreach ( $notices as $notice ) :
if ( strpos( $notice['notice'], 'removed' ) === false ) : ?>
<div class="woocommerce-message"<?php echo wc_get_notice_data_attr( $notice ); ?> role="alert">
<?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
<?php endif;
endforeach; ?>
Had to have add the 'notice' array key to the strpos method or it wasn't finding the "removed" string within the notice message. Hope this helps others who were having issues attempting to use this template override method.
There is a very simple answer to this problem as there is a hook that you can plug onto.
// This line is to be added in the functions.php
add_filter('woocommerce_cart_item_removed_notice_type', '__return_null');
1. Easy way: in wp-content/plugins/woocommerce/includes/class-wc-form-handler.php
2. remove/disable this line: wc_add_notice( $removed_notice ); (line 523) like this
if ( $product && $product->is_in_stock() && $product->has_enough_stock( $cart_item['quantity'] ) ) {
$removed_notice = sprintf( __( '%s removed.', 'woocommerce' ), $item_removed_title );
$removed_notice .= ' ' . __( 'Undo?', 'woocommerce' ) . '';
} else {
$removed_notice = sprintf( __( '%s removed.', 'woocommerce' ), $item_removed_title );
}
// wc_add_notice( $removed_notice );
}