I use WooCommerce & WPML for my client. The website have different prices for different markets.
For example, the EU is a price and for Finland there is another price both in €.
I have included a separate version of currency called FI-EUR. Everything appears right and works just the way I want.
add_filter( 'woocommerce_currencies', 'finland_euro' );
function finland_euro( $currencies ) {
$currencies['FI-EUR'] = __( 'Finland Euro', '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 'FI-EUR': $currency_symbol = '€'; break;
}
return $currency_symbol;
}
But the problem arises when we use Stripe or Paypal. Since it does not support FI-EUR. How do I change FI-EUR to EUR for stripe?
I can not overwrite EUR as there is another price.
Thank you!
Related
I would like on my site to be able to order the products page (woocommerce)
as well as with the classic settings
sort by popularity
sort by average rating
sort by newness
sort by price: low to high
sort by price: high to low
but also with an attribute present in all products
sort by my custom attribute: low to high
sort by my custom attribute: high to low
I found various posts about it and made several tests ... but I'm not a programmer ... I still haven't been able to solve the problem.
I found this article
https://docs.woocommerce.com/document/custom-sorting-options-ascdesc/
explaining how to add
sort by random
and it works correctly
but I didn't understand, starting from this code what you need to add / modify to replace random with my custom attribute.
My attribute name is "pa_kj"
Its value is alphanumeric
I thank everyone in advance for any suggestions
I found this code on the net
https://gist.github.com/bekarice/0df2b2d54d6ac8076f84
<?php
/**
* Adds WooCommerce catalog sorting options using postmeta, such as custom fields
* Tutorial: http://www.skyverge.com/blog/sort-woocommerce-products-custom-fields/
**/
function skyverge_add_postmeta_ordering_args( $sort_args ) {
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
switch( $orderby_value ) {
// Name your sortby key whatever you'd like; must correspond to the $sortby in the next function
case 'location':
$sort_args['orderby'] = 'meta_value';
// Sort by meta_value because we're using alphabetic sorting
$sort_args['order'] = 'asc';
$sort_args['meta_key'] = 'location';
// use the meta key you've set for your custom field, i.e., something like "location" or "_wholesale_price"
break;
case 'points_awarded':
$sort_args['orderby'] = 'meta_value_num';
// We use meta_value_num here because points are a number and we want to sort in numerical order
$sort_args['order'] = 'desc';
$sort_args['meta_key'] = 'points';
break;
}
return $sort_args;
}
add_filter( 'woocommerce_get_catalog_ordering_args', 'skyverge_add_postmeta_ordering_args' );
// Add these new sorting arguments to the sortby options on the frontend
function skyverge_add_new_postmeta_orderby( $sortby ) {
// Adjust the text as desired
$sortby['location'] = __( 'Sort by location', 'woocommerce' );
$sortby['points_awarded'] = __( 'Sort by points for purchase', 'woocommerce' );
return $sortby;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'skyverge_add_new_postmeta_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'skyverge_add_new_postmeta_orderby' );
but it doesn't work with the latest version of Woocommerce, it always returns the page with no products found.
Is there anyone experienced who can recommend the code to be modified?
Thanks again
I want to remove special word woocommerce products title
Example:
Products title: vidaXL Dining Chairs 2 pcs Solid Acacia Wood Sheesham
So, I want to remove vidaXL from WooCommerce website. This website still, 18000 products available so manually is not possible. If possible then please any WooCommerce functions.
I already tried so please someone help me.
add_filter( 'gettext', 'theme_change_field_names', 20, 3 );
function theme_change_field_names( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'vidaXL' :
$translated_text = __( '', 'theme_text_domain' );
break;
}
return $translated_text;
}
The following code works correctly for single products, but I want to use this code for multiple variations of several kinds of products.
Actually, this code is adding the sale price with the original price before the sale price starts.
I am working on scheduling sales and I want to show both the sale price and the original, pre-sale price so that customers can see how much the discount will save them.
function cw_change_product_price_display( $price_html ) {
global $product;
global $woocommerce;
if ( $product->is_on_sale() ) {
return $price_html;
} elseif($product->get_sale_price()){
$price =wc_price($product->get_sale_price());
return $price_html . $price;
} else {
return $price_html;
}
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
I think your question is not clear but it seems that you should use the following hook to change the variable price of WooCommerce.
add_filter('woocommerce_product_variation_get_price', 'cw_change_product_price_display', 99, 2);
Does anybody know how to disable the Postcode validation on the checkout page in WooCommerce?
My country is set up as Switzerland, but I want also people from Austria and Germany allow to order.
So when I enter a German Postcode with 5 digits (in Switzerland there are only 4), the shop says it's an invalid postcode. (but in the settings I allowed every country).
Any idea how to fix that?
Adding this code to the functions.php file should work:
function custom_override_default_address_fields( $address_fields )
{
unset( $address_fields['postcode'] );
return $address_fields;
}
EDIT:
// Hook into the checkout fields (shipping & billing)
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Hook into the default fields
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
function custom_override_checkout_fields( $fields )
{
unset( $fields['billing']['billing_postcode'] );
unset( $fields['shipping']['shipping_postcode'] );
return $fields;
}
function custom_override_default_address_fields( $address_fields )
{
unset( $address_fields['postcode'] );
return $address_fields;
}
ANOTHER EDIT:
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
function custom_override_default_address_fields( $address_fields )
{
$address_fields['postcode']['required'] = false;
return $address_fields;
}
So I didn't actually find a simple code solution for this one but I noticed that if I set
WooCommerce > Preferences > General > Geolocate address
it will work (if settings are set to "Sell to all countries", in my case)
This code only removes validation of address fields in my-account page, what you need:
add_filter( 'woocommerce_default_address_fields',
'custom_override_default_address_fields' );
function custom_override_default_address_fields($address_fields)
{
$address_fields['postcode']['validate'] = false;
return $address_fields;
}
for billing and shipping:
add_filter( 'woocommerce_checkout_fields' , 'remove_postcode_validation', 99 );
function remove_postcode_validation( $fields ) {
unset($fields['billing']['billing_postcode']['validate']);
unset($fields['shipping']['shipping_postcode']['validate']);
return $fields;
}
Also i think with removing "validate-required" class in wc-template-function.php, this feature will be deactivated (no test).
Sorry for bad English and hope this solutions solve your problem.
The previous answers don't seem to address the question! The postcode is still a required field, it's matter of whether other postcodes can be allowed that WooCommerce is saying is wrong.
For a checkout I'm building I've used this filter to allow any postcode to be considered valid regardless of country/postcode given.
add_filter( 'woocommerce_validate_postcode' , 'mycode_override_postcode_check', 99, 3 );
function mycode_override_postcode_check( $valid, $postcode, $country ) {
return true;
}
You can change that return true; for more complex code logic that reviews the postcode and country, this can help if your version of WooCommerce doesn't cover new postcode/zip code rules and you need them to be accepted.
Source: https://github.com/EloxZ/wordpresscrm/blob/main/wp-content/plugins/woocommerce/includes/class-wc-validation.php#L123
I am working on a plugin for woocommerce and came across the hook "woocommerce_variation_price_html" which allows you to hook into the variation prices drop down on single products. So created a quick function to test and have a play:
add_action( 'woocommerce_variation_price_html' , 'wholesale_variation_price' );
function wholesale_variation_price($term){
return '';
}
The above works nicely and removes all data. However i am trying to add custom meta_data to replace the default values.
So i then did the following:
add_action( 'woocommerce_variation_price_html' , 'wholesale_variation_price' );
function wholesale_variation_price($term){
$var_price = get_post_meta( get_the_id(), '_my_price', true );
return $var_price;
}
This for some reason does not work? Has anyone had any experience working with this hook in woocommerce? There is not much documentation on that hook anywhere.
Any help would be greatly appreciated!
As already indicated that you can read here about filters for html.
Maybe you have Sale price set for variation? Then in link you can see that there are total of 4 filters. For: price, sale price, free and no price.
This code works
add_filter( 'woocommerce_variation_sale_price_html', 'my_html', 10, 2);
add_filter( 'woocommerce_variation_price_html', 'my_html', 10, 2);
function my_html( $price, $variation ) {
return woocommerce_price(5);
}
Also this one works too. This allows you to modify whole variation. Read in code here
add_filter( 'woocommerce_available_variation', 'my_variation', 10, 3);
function my_variation( $data, $product, $variation ) {
$data['price_html'] = woocommerce_price(6);
return $data;
}
Screenshots:
First example
Second example
Works like magic!
P.S. you can see prices like this in screenshots because I have design that show them like that.
EDIT 2016-09-10
Version 2.6+
As woocommerce_price is deprecated in 2.6 then use wc_price for newer versions.
// Display Price For Variable Product With Same Variations Prices
add_filter('woocommerce_available_variation', function ($value, $object = null, $variation = null) {
if ($value['price_html'] == '') {
$value['price_html'] = '<span class="price">' . $variation->get_price_html() . '</span>';
}
return $value;}, 10, 3);
By looking at WooCommerce source code, I see that woocommerce_variation_price_html is a filter, not an action. I don't know how you managed to get your sample code to work like that... weird.
Try this:
function wholesale_variation_price( $price, $product ) {
$var_price = get_post_meta( $product->variation_id, '_my_price', true );
return $var_price;
}
add_filter( 'woocommerce_variation_price_html', 'wholesale_variation_price', 10, 2 )
I used this to modify the variation prices to show the price for each variation product excluding tax before and including tax after :)
add_filter( 'woocommerce_available_variation', 'my_variation', 10, 3);
function my_variation( $data, $product, $variation ) {
$data['price_html'] = "<span class='ex-vat-price'>ex. " . woocommerce_price($variation->get_price_excluding_tax()) . "</span><br>";
$data['price_html'] .= "<span class='inc-vat-price'>inc. " . woocommerce_price($variation->get_price_including_tax()) . "</span>";
return $data;
}