Wordpress woocommerce price displaiyng issue - php

I'm trying to solve issue about displaying price in wordpress woocomerce. The preview site (loop) works fine also the single product page prices shows well. Only the variable price doesn't change with selection field. The main problem why I create filter for prices is displaying price with tax and without. My code look like :
add_filter('woocommerce_get_price_html', 'edit_price_display', 10, 2);
function edit_price_display() {
global $product;
$price = $product->get_price();
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
if (!empty($tax_rates)) {
$tax_rate = reset($tax_rates);
}
if($product->is_type( 'simple' ) && is_numeric($price)) {
$price_incl_tax = $price + round($price * ( $tax_rate['rate'] / 100 ), 2);
$price_incl_tax = wc_price($price_incl_tax);
$price = wc_price($price);
$display_price = '<span class="price">';
$display_price .= '<span class="amount">' . $price_incl_tax .' s DPH </span>';
$display_price .= '<br>';
$display_price .= '<span class="amount">' . $price .' bez DPH </span>';
$display_price .= '</span>';
return $display_price;
}
if($product->is_type( 'variable' ) && is_numeric($price) && !is_single()) {
$minmax = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
if($minmax[0] == $minmax[1]){
$price_incl_tax = $minmax[0] + round($minmax[0] * ( $tax_rate['rate'] / 100 ), 2);
$price_incl_tax = wc_price($price_incl_tax);
$price = wc_price($minmax[0]);
$display_price = '<span class="price">';
$display_price .= '<span class="amount">' . $price_incl_tax .' s DPH </span>';
$display_price .= '<br>';
$display_price .= '<span class="amount">' . $price .' bez DPH </span>';
$display_price .= '</span>';
}
if($minmax[0] != $minmax[1]){
$price_incl_tax_min = $minmax[0] + round($minmax[0] * ( $tax_rate['rate'] / 100 ), 2);
$price_incl_tax_min = wc_price($price_incl_tax_min);
$price_incl_tax_max = $minmax[1] + round($minmax[1] * ( $tax_rate['rate'] / 100 ), 2);
$price_incl_tax_max = wc_price($price_incl_tax_max);
$price_excl_tax_min = wc_price($minmax[0]);
$price_excl_tax_max = wc_price($minmax[1]);
$display_price = '<span class="price">';
$display_price .= '<span class="amount">' .$price_incl_tax_min. ' - ' .$price_incl_tax_max. ' s DPH </span>';
$display_price .= '<br>';
$display_price .= '<span class="amount">' . $price_excl_tax_min .' - '.$price_excl_tax_max.' bez DPH </span>';
$display_price .= '</span>';
}
return $display_price;
}
if($product->is_type( 'variable' ) && is_numeric($price) && is_single()) {
return $product->price; // Issue is right her !
}
if( $price == '' || $price == '-' ) {
$display_price = '<span class="amount">Cena na dopyt</span>';
return $display_price;
}
}
I think the problem is in (multidimensional) array filling. Because the variation.php file handling the price show up for variable product. In the variation we can see something like :
<script type="text/template" id="tmpl-variation-template">
<div class="woocommerce-variation-description">{{{ data.variation.variation_description }}}</div>
<div class="woocommerce-variation-price">{{{ data.variation.price_html }}}</div>
<div class="woocommerce-variation-availability">{{{ data.variation.availability_html }}}</div>
</script>
But I have no idea how that mentioned array looks like ?

It is not the best solution to modify riginal loop/price.php file but it is quick. The final code looks like:
global $product;
if ( $price_html = $product->get_price_html() ) {
$price = $product->get_price();
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
if (!empty($tax_rates)) {
$tax_rate = reset($tax_rates);
}
if ( '' === $price || 0 == $price ) {
$display_price = $price_html;
}
if($product->is_type( 'simple' ) && is_numeric($price)) {
$price_incl_tax = round($price * (1 + ($tax_rate['rate'] / 100) ), 2);
$price_incl_tax = wc_price($price_incl_tax);
$price = wc_price($price);
$display_price = '<span class="price">';
$display_price .= '<span class="amount">' . $price_incl_tax .' s DPH </span>';
$display_price .= '<br>';
$display_price .= '<span class="amount">' . $price .' bez DPH </span>';
$display_price .= '</span>';
}
if($product->is_type( 'variable' ) && is_numeric($price) && $price > 0) {
$minmax = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
if($minmax[0] == $minmax[1]){
$price_excl_tax = round($minmax[0] / (1 + ($tax_rate['rate'] / 100) ), 2);
$price_excl_tax = wc_price($price_excl_tax);
$price = wc_price($minmax[0]);
$display_price = '<span class="price">';
$display_price .= '<span class="amount">' . $price .' s DPH </span>';
$display_price .= '<br>';
$display_price .= '<span class="amount">' . $price_excl_tax .' bez DPH </span>';
$display_price .= '</span>';
}
if($minmax[0] != $minmax[1]){
$price_excl_tax_min = round($minmax[0] / (1 + ($tax_rate['rate'] / 100) ), 2);
$price_excl_tax_min = wc_price($price_excl_tax_min);
$price_excl_tax_max = round($minmax[1] / (1 + ($tax_rate['rate'] / 100) ), 2);
$price_excl_tax_max = wc_price($price_excl_tax_max);
$price_incl_tax_min = wc_price($minmax[0]);
$price_incl_tax_max = wc_price($minmax[1]);
$display_price = '<span class="price">';
$display_price .= '<span class="amount">' .$price_incl_tax_min. ' - ' .$price_incl_tax_max. ' s DPH </span>';
$display_price .= '<br>';
$display_price .= '<span class="amount">' . $price_excl_tax_min .' - '.$price_excl_tax_max.' bez DPH </span>';
$display_price .= '</span>';
}
}
echo $display_price;
}
And for single product page use shortcode {price_excluding_tax} as price suffix located in woocommerce tax.

Related

WooCommerce how to display "you save X%" on checkout page

I have made a function that displays on checkout the total savings based on product discounts but I would like it to show the percentage saved above the order total, and if possible show it inside of a box.
Code:
function wc_discount_total() {
global $woocommerce;
$discount_total = 0;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
if ( $_product->is_on_sale() ) {
$regular_price = $_product->get_regular_price();
$sale_price = $_product->get_sale_price();
$discount = ($regular_price - $sale_price) * $values['quantity'];
$discount_total += $discount;
}
}
if ( $discount_total > 0 ) {
echo '<tr class="cart-discount">
<th>'. __( 'Your Savings', 'woocommerce' ) .'</th>
<td data-title=" '. __( 'You Saved', 'woocommerce' ) .' ">'
. wc_price( $discount_total + $woocommerce->cart->discount_cart ) .'</td>
</tr>';
}
}
add_action( 'woocommerce_cart_totals_after_order_total', 'wc_discount_total', 99);
add_action( 'woocommerce_review_order_after_order_total', 'wc_discount_total', 99);
How my current checkout looks like:
Zoomed:
How I would like it to look:
If there is a discount on that order, then you could add another table row tag and calculate the percentage. So it'd be something like this:
add_action('woocommerce_cart_totals_after_order_total', 'wc_discount_total', 99);
add_action('woocommerce_review_order_after_order_total', 'wc_discount_total', 99);
function wc_discount_total()
{
global $woocommerce;
$discount_total = 0;
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
if ($_product->is_on_sale()) {
$regular_price = $_product->get_regular_price();
$sale_price = $_product->get_sale_price();
$discount = ($regular_price - $sale_price) * $values['quantity'];
$discount_total += $discount;
}
}
if ($discount_total > 0) {
echo '<tr class="cart-discount">
<th>' . __('Your Savings', 'woocommerce') . '</th>
<td data-title=" ' . __('You Saved', 'woocommerce') . ' ">'
. wc_price($discount_total + $woocommerce->cart->discount_cart) . '</td>
</tr>';
$total = WC()->cart->cart_contents_total;
$total_saved = wc_price($discount_total + $woocommerce->cart->discount_cart);
$percentage_saved = round(($total_saved * 100) / $total);
echo '<tr class="cart-percentage-discount">
<th>' . __('Percentage Saved', 'woocommerce') . '</th>
<td data-title=" ' . __('You Saved', 'woocommerce') . ' ">' . esc_html($percentage_saved . "%") . '</td>
</tr>';
}
}

Add sale badge to product thumbnail on single product page and shop archive pages in WooCommerce

I use the following code to add a small badge topleft of every product with -%off.
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'filter_woocommerce_single_product_image_thumbnail_html', 10, 2 );
function filter_woocommerce_single_product_image_thumbnail_html( $thumbnail, $thumbnail_id ) {
global $post, $woocommerce;
$product = wc_get_product( $post->ID );
$is_on_sale = $product->is_on_sale();
if ( $is_on_sale ) {
$rrp_price = $product->get_regular_price();
$sale_price = $product->get_price();
$discount_amount = $rrp_price - $sale_price;
$discount_percent = '-' . round( ( $discount_amount / $rrp_price ) * 100, 0 ) . '%';
$thumbnail = '<span class="wpd-sale-thumbnail"><span class="wpd-sale-badge">' . $discount_percent . '</span>' . $thumbnail . '</span>';
}
return $thumbnail;
}
On my product page and it works. However when i try to do it on category page to all product listings with the following code:
add_filter( 'post_thumbnail_html', 'filter_woocommerce_archive_product_image_thumbnail_html', 30, 5 );
function filter_woocommerce_archive_product_image_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
$product = wc_get_product( $post_id );
if ( ! is_a( $product, 'WC_Product' ) ) {
return $html;
}
$is_on_sale = $product->is_on_sale();
if ( $is_on_sale && is_product_category() ) {
$rrp_price = $product->get_regular_price();
$sale_price = $product->get_price();
$discount_amount = $rrp_price - $sale_price;
$discount_percent = '-' . round( ( $discount_amount / $rrp_price ) * 100, 0 ) . '%';
$html = '<span class="wpd-sale-thumbnail"><span class="wpd-sale-badge">' . $discount_percent . '</span>' . $html . '</span>';
}
return $html;
}
It does not work, there doesn't seem to be any adjustment. Can I get some guidance into it?
To add the badge to the product images on the archive pages, either you use
/**
* Get the product thumbnail for the loop.
*/
function woocommerce_template_loop_product_thumbnail() {
$w_g_p_t = woocommerce_get_product_thumbnail();
global $product;
// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
// On sale
$is_on_sale = $product->is_on_sale();
// True
if ( $is_on_sale ) {
$rrp_price = (int) $product->get_regular_price();
$sale_price = (int) $product->get_price();
// Greater than
if ( $rrp_price > $sale_price ) {
$discount_amount = $rrp_price - $sale_price;
$discount_percent = '-' . round( ( $discount_amount / $rrp_price ) * 100, 0 ) . '%';
$w_g_p_t = '<span class="wpd-sale-thumbnail"><span class="wpd-sale-badge">' . $discount_percent . '</span>' . $w_g_p_t . '</span>';
}
}
}
echo $w_g_p_t;
}
OR
function action_woocommerce_before_shop_loop_item_title() {
// Removes a function from a specified action hook.
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
global $product;
// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
$size = 'woocommerce_thumbnail';
$image_size = apply_filters( 'single_product_archive_thumbnail_size', $size );
$get_image = $product->get_image( $image_size );
// On sale
$is_on_sale = $product->is_on_sale();
// True
if ( $is_on_sale ) {
$rrp_price = (int) $product->get_regular_price();
$sale_price = (int) $product->get_price();
// Greater than
if ( $rrp_price > $sale_price ) {
$discount_amount = $rrp_price - $sale_price;
$discount_percent = '-' . round( ( $discount_amount / $rrp_price ) * 100, 0 ) . '%';
$get_image = '<span class="wpd-sale-thumbnail"><span class="wpd-sale-badge">' . $discount_percent . '</span>' . $get_image . '</span>';
}
}
}
echo $product ? $get_image : '';
}
add_action( 'woocommerce_before_shop_loop_item_title', 'action_woocommerce_before_shop_loop_item_title', 9 );
I have also rewritten your existing code (for the single product page)
function filter_woocommerce_single_product_image_thumbnail_html( $html, $post_thumbnail_id ) {
// Get the global product object
global $product;
// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
// On sale
$is_on_sale = $product->is_on_sale();
// True
if ( $is_on_sale ) {
$rrp_price = (int) $product->get_regular_price();
$sale_price = (int) $product->get_price();
// Greater than
if ( $rrp_price > $sale_price ) {
$discount_amount = $rrp_price - $sale_price;
$discount_percent = '-' . round( ( $discount_amount / $rrp_price ) * 100, 0 ) . '%';
$html = '<span class="wpd-sale-thumbnail"><span class="wpd-sale-badge">' . $discount_percent . '</span>' . $html . '</span>';
}
}
}
return $html;
}
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'filter_woocommerce_single_product_image_thumbnail_html', 10, 2 );

Passing default arguments value in function not working

First of all, sorry for my lack of knowledge in PHP. I have tried googling for the answer, and also tried several answers here. For some reason passing argument in my function isn't working. However, if I directly call the default value in function, it works. Here is the function I am using.
function pnet_breadcrumbs( $seperator = '»', $home = true, $blog = true, $show_hierarchy = true ) {
global $post, $wp_query;
$html = '<div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">';
$position = 1;
if ( $home ) {
$html .= '<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to ' . get_option( 'blogname' ) . '." href="' . home_url( '/' ) . '" class="home"><span property="name">' . get_option( 'blogname' ) . '</span></a><meta property="position" content="' . $position . '"></span>' . $seperator;
$html .= ' ' . $seperator . ' '; //Not Working
$html .= ' » '; //Working
$position = $position + 1;
}
if ( is_tax() || is_category() || is_tag() ) {
$obj = $wp_query->get_queried_object();
if ( $show_hierarchy ) {
$ancestors = get_ancestors( $obj->term_id, $obj->taxonomy, 'taxonomy' );
if ( is_array($ancestors) && !empty($ancestors) ) {
$ancestors = array_reverse( $ancestors );
foreach( $ancestors as $ancestor ) {
$term_obj = get_term($ancestor);
$term_url = get_term_link($term_obj->term_id);
$html .= '<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="' . sprintf( __( 'View Archive for %s.', 'pnet' ), $term_obj->name ) . '." href="' . $term_url . '" class="home"><span property="name">' . $term_obj->name . '</span></a><meta property="position" content="' . $position . '"></span>';
$html .= $seperator;
$position++;
}
}
}
$html .= '<span property="itemListElement" typeof="ListItem"><span property="name">' . $obj->name . '</span><meta property="position" content="' . $position . '"></span>';
}
if ( is_search() ) {
$html .= '<span property="itemListElement" typeof="ListItem"><span property="name">' . sprintf( __( 'Search results for %s.', 'pnet' ), get_search_query() ) . '</span><meta property="position" content="' . $position . '"></span>';
}
$html .= '</div>';
echo $html;
}
add_action( 'wp_footer', 'pnet_breadcrumbs', 0 );
The variable $seperator is returning empty.
I know this is basic PHP, but I really can't figure out why I can't use a default value. What am I doing wrong?

Display Sale Price Before Regular Price (WooCommerce)

I'd like to display the sale price of a product before the regular (discounted) price. I know this has something to do with get_price_html. By default, this outputs something like:
<del>regular price</del>
<ins>sale price</ins>
I want to change the output so it looks like this (basically, the two prices are shown in a different order):
<ins>sale price</ins>
<del>regular price</del>
How can I do this?
Yes you have to alter get_price_html method which can be done by
using following hook's:
For Simple Product: woocommerce_get_price_html hook.
For Variable Product: woocommerce_variation_sale_price_html & woocommerce_variation_price_html
For Variable Product Min Max Price: woocommerce_variable_sale_price_html &
woocommerce_variable_price_html
UPDATED 16th Feb 2018
Here is the code:
For WooCommerce version 2.6.x or below
if (!function_exists('my_commonPriceHtml')) {
function my_commonPriceHtml($price_amt, $regular_price, $sale_price) {
$html_price = '<p class="price">';
//if product is in sale
if (($price_amt == $sale_price) && ($sale_price != 0)) {
$html_price .= '<ins>' . woocommerce_price($sale_price) . '</ins>';
$html_price .= '<del>' . woocommerce_price($regular_price) . '</del>';
}
//in sale but free
else if (($price_amt == $sale_price) && ($sale_price == 0)) {
$html_price .= '<ins>Free!</ins>';
$html_price .= '<del>' . woocommerce_price($regular_price) . '</del>';
}
//not is sale
else if (($price_amt == $regular_price) && ($regular_price != 0)) {
$html_price .= '<ins>' . woocommerce_price($regular_price) . '</ins>';
}
//for free product
else if (($price_amt == $regular_price) && ($regular_price == 0)) {
$html_price .= '<ins>Free!</ins>';
}
$html_price .= '</p>';
return $html_price;
}
}
add_filter('woocommerce_get_price_html', 'my_simple_product_price_html', 100, 2);
function my_simple_product_price_html($price, $product) {
if ($product->is_type('simple')) {
$regular_price = $product->regular_price;
$sale_price = $product->sale_price;
$price_amt = $product->price;
return my_commonPriceHtml($price_amt, $regular_price, $sale_price);
} else {
return $price;
}
}
add_filter('woocommerce_variation_sale_price_html', 'my_variable_product_price_html', 10, 2);
add_filter('woocommerce_variation_price_html', 'my_variable_product_price_html', 10, 2);
function my_variable_product_price_html($price, $variation) {
$variation_id = $variation->variation_id;
//creating the product object
$variable_product = new WC_Product($variation_id);
$regular_price = $variable_product->regular_price;
$sale_price = $variable_product->sale_price;
$price_amt = $variable_product->price;
return my_commonPriceHtml($price_amt, $regular_price, $sale_price);
}
add_filter('woocommerce_variable_sale_price_html', 'my_variable_product_minmax_price_html', 10, 2);
add_filter('woocommerce_variable_price_html', 'my_variable_product_minmax_price_html', 10, 2);
function my_variable_product_minmax_price_html($price, $product) {
$variation_min_price = $product->get_variation_price('min', true);
$variation_max_price = $product->get_variation_price('max', true);
$variation_min_regular_price = $product->get_variation_regular_price('min', true);
$variation_max_regular_price = $product->get_variation_regular_price('max', true);
if (($variation_min_price == $variation_min_regular_price) && ($variation_max_price == $variation_max_regular_price)) {
$html_min_max_price = $price;
} else {
$html_price = '<p class="price">';
$html_price .= '<ins>' . woocommerce_price($variation_min_price) . '-' . woocommerce_price($variation_max_price) . '</ins>';
$html_price .= '<del>' . woocommerce_price($variation_min_regular_price) . '-' . woocommerce_price($variation_max_regular_price) . '</del>';
$html_min_max_price = $html_price;
}
return $html_min_max_price;
}
For WooCommerce version 3.0 or above
if (!function_exists('my_commonPriceHtml')) {
function my_commonPriceHtml($price_amt, $regular_price, $sale_price) {
$html_price = '<p class="price">';
//if product is in sale
if (($price_amt == $sale_price) && ($sale_price != 0)) {
$html_price .= '<ins>' . wc_price($sale_price) . '</ins>';
$html_price .= '<del>' . wc_price($regular_price) . '</del>';
}
//in sale but free
else if (($price_amt == $sale_price) && ($sale_price == 0)) {
$html_price .= '<ins>Free!</ins>';
$html_price .= '<del>' . wc_price($regular_price) . '</del>';
}
//not is sale
else if (($price_amt == $regular_price) && ($regular_price != 0)) {
$html_price .= '<ins>' . wc_price($regular_price) . '</ins>';
}
//for free product
else if (($price_amt == $regular_price) && ($regular_price == 0)) {
$html_price .= '<ins>Free!</ins>';
}
$html_price .= '</p>';
return $html_price;
}
}
add_filter('woocommerce_get_price_html', 'my_simple_product_price_html', 100, 2);
function my_simple_product_price_html($price, $product) {
if ($product->is_type('simple')) {
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
$price_amt = $product->get_price();
return my_commonPriceHtml($price_amt, $regular_price, $sale_price);
} else {
return $price;
}
}
add_filter('woocommerce_variation_sale_price_html', 'my_variable_product_price_html', 10, 2);
add_filter('woocommerce_variation_price_html', 'my_variable_product_price_html', 10, 2);
function my_variable_product_price_html($price, $variation) {
$variation_id = $variation->variation_id;
//creating the product object
$variable_product = new WC_Product($variation_id);
$regular_price = $variable_product->get_regular_price();
$sale_price = $variable_product->get_sale_price();
$price_amt = $variable_product->get_price();
return my_commonPriceHtml($price_amt, $regular_price, $sale_price);
}
add_filter('woocommerce_variable_sale_price_html', 'my_variable_product_minmax_price_html', 10, 2);
add_filter('woocommerce_variable_price_html', 'my_variable_product_minmax_price_html', 10, 2);
function my_variable_product_minmax_price_html($price, $product) {
$variation_min_price = $product->get_variation_price('min', true);
$variation_max_price = $product->get_variation_price('max', true);
$variation_min_regular_price = $product->get_variation_regular_price('min', true);
$variation_max_regular_price = $product->get_variation_regular_price('max', true);
if (($variation_min_price == $variation_min_regular_price) && ($variation_max_price == $variation_max_regular_price)) {
$html_min_max_price = $price;
} else {
$html_price = '<p class="price">';
$html_price .= '<ins>' . wc_price($variation_min_price) . '-' . wc_price($variation_max_price) . '</ins>';
$html_price .= '<del>' . wc_price($variation_min_regular_price) . '-' . wc_price($variation_max_regular_price) . '</del>';
$html_min_max_price = $html_price;
}
return $html_min_max_price;
}
Code goes in functions.php file of your active child theme (or theme). Or also in any plugin php files.
Code is tested and works.
Hope this helps!

WooCommerce custom function for Free Shipping Label

When i put the following into to my functions.php it crashes my entire site.
the purpose of this function is to change
elseif ( $method->id !== 'free_shipping' ) {
$label .= ' (' . __( '**Free**', 'woocommerce' ) . ')';
to this...
elseif ( $method->id !== 'free_shipping' ) {
$label .= ' (' . __( '**To Be Calculated**', 'woocommerce' ) . ')';
When i change the one word in the original woocommerce/includes/wc-cart-functions.php it works perfectly. I don't want it to be overwritten with an update.
/**
* Get a shipping methods full label including price
* #param object $method
* #return string
*/
function wc_cart_totals_shipping_method_label( $method ) {
$label = $method->label;
if ( $method->cost > 0 ) {
if ( WC()->cart->tax_display_cart == 'excl' ) {
$label .= ': ' . wc_price( $method->cost );
if ( $method->get_shipping_tax() > 0 && WC()->cart->prices_include_tax ) {
$label .= ' <small>' . WC()->countries->ex_tax_or_vat() . '</small>';
}
} else {
$label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
if ( $method->get_shipping_tax() > 0 && ! WC()->cart->prices_include_tax ) {
$label .= ' <small>' . WC()->countries->inc_tax_or_vat() . '</small>';
}
}
} elseif ( $method->id !== 'free_shipping' ) {
$label .= ' (' . __( 'To Be Calculated', 'woocommerce' ) . ')';
}
return apply_filters( 'woocommerce_cart_shipping_method_full_label', $label, $method );
}
if you are using latest woo commerce then following filter will be helpful to you.
add_filter( 'woocommerce_cart_shipping_method_full_label', 'remove_local_pickup_free_label', 10, 2 );
function remove_local_pickup_free_label($full_label, $method){
$full_label = str_replace("(Free)","(TBD)",$full_label);
return $full_label;
}
You should rebuild the function through the filter. Using str_replace will not work on translated installs, unless each language is checked in the replacement.
function ua_woocommerce_cart_shipping_method_full_label( $label, $method ) {
$label = $method->label;
if ( $method->cost > 0 ) {
if ( WC()->cart->tax_display_cart == 'excl' ) {
$label .= ': ' . wc_price( $method->cost );
if ( $method->get_shipping_tax() > 0 && WC()->cart->prices_include_tax ) {
$label .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
}
} else {
$label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
if ( $method->get_shipping_tax() > 0 && ! WC()->cart->prices_include_tax ) {
$label .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
}
}
}
return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'ua_woocommerce_cart_shipping_method_full_label', 10, 2 );

Categories