decimal separator in woocommerce to be a comma - woocommerce

I have a woocommerce shop in which I have set up my prices (in settings) to have the decimal separator to be a comma instead of a dot (EURO system).
The problem is in the code I need to add. There is this part:
$price_excl_vat = wc_get_price_excluding_tax( $product ); // Unit price excluding VAT
and this
<?php echo $items_string;
where it returns the prices with a dot.
Any tips on how to make it give the prices with a comma?

You can use the function number_format( $price_excl_vat, 2, ',', ' ' ); to format your price with the decimal separator set as comma.
http://php.net/manual/en/function.number-format.php
You could also use the woocommerce function wc_price( $price_excl_vat, array( 'decimal_separator' => ',' ) );. This function wil return a formatted price with a currency symbol and the decimal separator set as comma.
http://woocommerce.wp-a2z.org/oik_api/wc_price/

Related

ACF pro - return day with date picker

I use ACF pro for my wordpress.
My datepicker field is a repeater field.
I need to return only the day.
my code :
<?php
if( have_rows('dates') ):
while ( have_rows('dates') ) : the_row();
echo get_sub_field('date')."</br>";
endwhile;
else :
echo __( 'No dates available.','mywebsite' );
endif;
?>
You can set the return value of the date field.
EDIT
Ok, so if you want to display two dates, one full and one is only day, you first need the return value to be the full date, for this example lets day it d/m/Y
$full_date = get_sub_field('date'); // the full date (format d/m/Y);
$day_from_date = DateTime::createFromFormat('d/m/Y', $full_date)->format('d'); // will get the day from the $full_date
This will get you the result you need.
See DateTime::createFromFormat for more information about the method
The get_sub_field() function would typically return a string depending on the field type. This instance it will return a timestamp as as string eg '2021-06-28 10:28:00'
If you want to return the day only you could use PHP's strtotime function which will then return you a datetime epoch integer - this can then be used in conjunction with php's date function to print as the day. Here is a list of the formats you can use for the date function : PHP DateTime::format
Example :
<?php
if (have_rows('dates')):
while (have_rows('dates')) : the_row();
$dateTime = strtotime(get_sub_field('date'));
echo("Day : " . date('l', $dateTime) . "</br>");
endwhile;
else :
echo __('No dates available.', 'mywebsite');
endif;
?>
As another solution which is within your setup rather than your code - change the 'Return Format' of the actual field.
See : ACF Date Time Picker Docs
Examples would be :
'd' - Day of the month, 2 digits with leading zeros
'j' - Day of the month without leading zeros
'D' - A textual representation of a day, three letters
'l' - A full textual representation of the day of the week
Then your original code will output the correct format :
<?php
if( have_rows('dates') ):
while ( have_rows('dates') ) :
the_row();
echo('Day: ' . get_sub_field('date') . "</br>"); //This will now output your 'Return Format' in ACF setup
endwhile;
else :
echo __( 'No dates available.','mywebsite' );
endif;
?>

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!

Remove dollar sign from price of product in woocommerce

I want to remove dollar sign "$" from the product price in a certain section of single-product page. Here's my code which is not working.Please help.
global $product;
$price = $product->get_price_html();
$filter_price = preg_replace('/.00/', '', $price);
$new_price = str_replace( '$', '', $filter_price );
echo $new_price;
You could do this:
$price = $product->get_price();
$new_price = str_replace( '$', '', $price );
echo $new_price;
If you want to get the price in a product template then you dont have to declare global $product again. Also, this will get you the actual price of the product before the apply of VAT. You can calculate the VAT manually afterwards.

WooCommerce - Getting total products count in the cart - not their quantity

I have total cart quantity but I need count of products available in the cart. I donot want to show total quantity but want to show total products/orders in the cart.
Please help!
i had same issue in client project # jivith.com
But i resolved ...
Use in minicart / cart function replace total products count in the cart - not their quantity items
$_cartQty = count( WC()->cart->get_cart() );
**or** use sizeof (WC()->cart->get_cart());
i getting the total unique total products count in the cart instead of item of their quantity...
My demo code:
<span class="cart-items"><?php echo ($minicart_type == 'minicart-inline')
? '<span class="mobile-hide">' . sprintf( _n( '%d item', '%d items', $_cartQty, 'porto' ), $_cartQty ) . '</span><span class="mobile-show">' . $_cartQty . '</span>'
: (($_cartQty > 0) ? $_cartQty : '0'); ?></span>
You can get the total number of unique product is using WC()->cart->cart_contents. This contains an array of cart items. You can use array_unique() function to avoid repetition of the ids. So finally you can use array_count to get the count of unique products.
I things Following code will help you. I had a issue i want to show total product counts not their quantity in the cart option.
If you change on class-wc-cart.php file just change php function array_sum() to count() it will work.
public function get_cart_contents_count() {
return apply_filters( 'woocommerce_cart_contents_count', count( wp_list_pluck( $this->get_cart(), 'quantity' )) );
}

WooCommerce- change admin date format

I would like to change the WooCommerce date format from Y/m/d to d/m/Y. I have the Print invoice plug-in, and the dates are in the y/m/d format as taken from the date ordered in WooCommerce.
The below used to be a solution- but it no longer works for WP 4.0
http://www.remicorson.com/customize-woocommerce-admin-orders-date-format/
add_filter('gettext', 'wpse_77783_woo_bacs_ibn', 10, 3);
add_filter( 'post_date_column_time' , 'woo_custom_post_date_column_time' );
// change default admin orders date format
add_filter( 'post_date_column_time' , 'woo_custom_post_date_column_time' );
function woo_custom_post_date_column_time( $post ) {
$h_time = get_the_time( __( 'm/d/Y', 'woocommerce' ), $post );
return $h_time;
}
Can anyone advise me here?
You also have to change the value of '$t_time' variable using the same 'post_date_column_time' filter.You have to return two values ($t_time and $h_time) using two separate callback functions. Your code will work when you add following callback on same filter in addition to your code.
add_filter( 'post_date_column_time' ,'woo_custom_post_date_column_time_withDate' );
function woo_custom_post_date_column_time_withDate( $post ) {
$t_time = get_the_time( __( 'd/m/Y g:i:s A', 'woocommerce' ), $post );
return $t_time;
}
(Also check the format you have set into the call back function, change it to 'd/m/Y' since you require it.)
This answer is no longer valid for newer versions. For version 3 and up, please see WooCommerce 3.0+ change admin order date column format.

Resources