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 :)
Related
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 );
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;
}
I am beginner on WordPress.
I want to get two things done on my WordPress site.
No 1: I want to make checkbox just with the word "Total"
No:2: When user would hit the checkbox, the quantity selector
must be disabled or diapered and only 1 item must be added into cart.
Please help me out, how can i do that.
Thanks in advance
if you want that customer will order only one quantity of product then you can do one thing is using woo-commerce
=> in product menu select add new product or edit nay product and GOTO product data below Editor and select inventory tab from that.
=> and select sold individually checkbox so this allow only one quantity for sell.
so you don't need to write any code for that.
and let me know if you want to write code for that.
I Hope this will work for you perfectly.
Thanks.
Edited :-
May i hope you got your answer this time
/**# Remove in all product type*/
function custom_remove_all_quantity_fields( $return, $product ) {return true;}
add_filter( 'woocommerce_is_sold_individually','custom_remove_all_quantity_fields', 10, 2 );
===================================
Edit for particular product
/**
* #Hide from different product type group
*/
add_filter( 'woocommerce_is_sold_individually', 'baztro_wc_remove_all_quantity_fields', 10, 2 );
function baztro_wc_remove_all_quantity_fields( $return, $product ) {
switch ( $product->product_type ) :
case "variable":
return true;
break;
case "grouped":
return true;
break;
case "external":
return true;
break;
default: // simple product type
return true;
break;
endswitch;
}
Here you go:
function add_checkbox_before_addtocart_quantity() {
?>
<div style="display:block; clear:both;"><input type="checkbox" id="totalcheck" name="subscribe" value="totalcheck"><label for="totalcheck"> Total</label></div>
<script>
(function( $ ) {
$('input#totalcheck').change(function () {
if(this.checked) {
// Set quantity to 1
$("input.input-text.qty.text").val("1");
// Hide quantity box
$(".quantity").hide();
}else{
// Show quantity box if total is not checked
$(".quantity").show();
}
});
})( jQuery );
</script>
<?php
};
add_action( 'woocommerce_before_add_to_cart_quantity', 'add_checkbox_before_addtocart_quantity', 10 );
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.
I am having a small problem which I believe to be related to a syntax issue.
I have a specific script for home which calls the bloginfo("name") for the page title then an else statement below which titles pages based on the name of the first category associated them and it works fine:
else{
$category = get_the_category();
echo $category[0]->cat_name;
}
However, I also have a default "home" category for most posts(with a few exceptions) and I do not want this category to be picked up as the page title if it happens to come first in the list of categories associated for this page.
There are two ways I can think of making this possible but I do not know how to code them. The first would be to exclude the home category in the code above but don't know how to implement it. The second would be to somehow force wordpress to always add the category "home" after the first chosen category for a particular post.
I hope that this is clear. Anyone come up with a basic solution?
Many thanks.
This plugin does most of what you want out of the box:
http://wordpress.org/extend/plugins/sem-opt-in-front/
Alternatively, do something like:
function the_main_topic_link($link = '', $id = '')
{
if (!$id || $id != get_option('default_category')) return $link;
if (get_option('show_on_front') == 'page' && get_option('page_on_front')) {
if ($blog_page_id = get_option('page_for_posts')) {
return apply_filters('the_permalink', get_permalink($blog_page_id));
} else {
return $link;
}
} else {
return home_url('/');
}
}
add_filter('category_link', 'the_main_topic_link', 10, 2);
function pre_get_posts_redirect_main_topic($q)
{
global $wp_the_query;
if ($q !== $wp_the_query) return;
if ($q->is_category(get_option('default_category'))) {
wp_redirect(home_url('/'));
die;
}
}
if (!is_admin()) add_action('pre_get_posts', 'pre_get_posts_redirect_main_topic');
It'll treat linking to your default category as linking to your front page.