How to wrap woocommerce currency symbol in span? - wordpress

How to wrap woocommerce currency symbol in span?
The question pretty much sums it all up. I want to style woocommerce currency symbol individually and i can't do it since it is outputted as text content with the price.
Please if anyone can help me, I would vary much appreciate it.
Thank you.

I figured it out :)
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
$currency_symbol = '<span>' . $currency_symbol . '</span>';
return $currency_symbol;
}

This way you can add custom currency in woocommerce :
add_filter('woocommerce_currencies', 'add_custom_currency');
function add_custom_currency($currencies) {
$currencies["SPAN"] = 'Span Euro';
return $currencies;
}
add_filter('woocommerce_currency_symbol', 'add_custom_currency_symbol', 10, 2);
function add_custom_currency_symbol($currency_symbol, $currency) {
switch ($currency) {
case 'SPAN': $currency_symbol = 'Sp';
break;
}
return $currency_symbol;
}
Here 'Sp' is the currency shown on your website.

Related

Solution to changing currency for Woocommerce products

Hi so I would like to be able to change currency for different products added to the cart/checkout.
I found solution that is filtering woocommerce_currency hook and using cart session to change currency.
Two questions:
Is there a better way of doing it?
Do you see any potential problems with the following solution?
public function modifyWoocommerceCurrency( $currency ) {
$cart_data = WC()->session->get('cart');
foreach ($cart_data as $item) {
if (isset($item["_campaign_options"]["user_paying_currency"])) {
$currency = $item['_campaign_options']['user_paying_currency'];
}
}
return $currency;
}
add_filter( 'woocommerce_currency', [$this,'modifyWoocommerceCurrency'], 10, 1 );

How to add dot with currency code in woocommerce plugin?

I want to add a dot with currency code, for example, my currency code is RS then I want this format (RS.) then the amount will be displayed.
I want this formate RS. 300 With my amount 300. kindly help me...
IN woocommerce I try many currency positions. for example in woocommerce they give us
left
right
left with space
right with space
But I also want "left with dot" and "right with dot".
how can I customize for this?
Is this not the decimal seperator? Maybe add this to . and then set the number of decimals to whatever you need
For This, You Must add a Custom Currency Symbol Try Adding bellow Code to your Functions.php in your child theme
/**
* Custom currency and currency symbol
*/
add_filter( 'woocommerce_currencies', 'add_my_currency' );
function add_my_currency( $currencies ) {
$currencies['Rs.'] = __( 'Pakistani Rupees', 'woocommerce' );
return $currencies;
}
add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);
function add_my_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'Rs.': $currency_symbol = 'Rs.'; break;
}
return $currency_symbol;
}

woocommerce_free_price_html not working

I used the following code to change the 0,00 to a text in Wordpress Woocommerce, but it doesn't work anymore:
add_filter('woocommerce_free_price_html', 'changeFreePriceNotice', 10, 2);
function changeFreePriceNotice($price, $product) {
return 'Call for price';
}
Does anyone know how to solve this? Google can't help me unfortunately. Hope somebody can help me!
Since WooCommerce 3.0 woocommerce_free_price_html does not work any more
I could not find the information why it no longer works.
But I found one solution and adapted it, making it more universal:
add_filter( 'woocommerce_get_price_html','custom_free_price_text' );
function custom_free_price_text( $product ) {
global $product;
$price = $product->get_price();
if($price == '0.00') {
return 'Call for price';
} else {
return "$ ".$price;
}
}

currency symbol replace specific

I am developing a new woocommerce site, and faced a new issue that I have not dealed with in other shops. I need to change the currency symbol to something else than the standard. In my country it's DKK. And my custom text should be "DKK / month" but only in the cart(product loop overview), not in total calculation(checkout section), because, for example, freight is not / month and totals is not either.
Following code is working great everywhere on the page, but it needs to be only in the cart listing/loop pr. product, and also btw in the reciept product listing.
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'DKK': $currency_symbol = 'kr. <span class="paymentType">/ month</span>'; break;
}
return $currency_symbol;
}
How do i change that to only appear at cart product loop?
I have tried with:
if(is_cart()){
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'DKK': $currency_symbol = 'kr. <span class="paymentType">/ month</span>'; break;
}
return $currency_symbol;
}
}
But is not working, and I am not sure that's it is the right approach.
Suggestions? :-)
Instead of dealing with above I ended up manually typing / month in the various template files (not core files) where the price was defined. Hope this will help someone else :)

Wordpress symbol in title

I want to remove symbol &raquo from title in wordpress. This symbol is add in every page before page title:
http://i.stack.imgur.com/7I5xf.png
You can use add_filter() for this purpose.
A simple example would be like
add_filter( 'the_title', 'lose_four_chars');
function lose_four_chars($title) {
if ( is_single()) {
return substr($title, 4);
} else {
return $title;
}
}
where lose_four_chars function can be replaced with your manual function..
Please have a look here

Resources