PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

WooCommerce Currency Switcher returning NULL as opposed to a string

This support system is for all types of the plugins as for premium versions, so for free ones! If you have premium version do not forget in the private data of the request (!!not in the text of the support request!!) after its publishing insert purchase code please (see blue-green button on the right side) and press Save button.
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi,

We currently use your WOOCS (Currency Switcher) plugin which is working well, however we have run into a problem involving another plugin we have just activated, WooCommerce Google Product Feed (this plugin enables us to list our products in Google via the Google Merchant Centre). Two products from our WooCommerce store were not feeding through correctly, so I asked the Google Product Feed plugin admin to investigate. They reverted with the below explanation:
" Hi Jono;

Thanks for that. I've looked at the debug output, and taking the product we discussed as an example (https://lifejacketskinprotection.com/product/daily-protection-moisturiser/) I've located the cause of the issue.

The plugin asks WooCommerce for information about the price of the products, specifically as well as the standard price, it also asks for the sale price. In this example, the call to get_sale_price() is returning an invalid value. The return value from that function should be a string, however on your site NULL is returned, which causes our plugin to believe the product has a zero sale price which leads to it being excluded from the feed (as zero-value items can't be submitted to Google).

Looking at the plugins installed on your site I believe it's the WOOCS Currency switcher plugin which is causing the issue.

If the WOOCS currency switcher plugin does turn out to be the issue, you'll need to contact the developers of that plugin and ask them to modify their plugin and ensure that it returns a correct value when they are filtering the results of get_sale_price() on WooCommerce products.

For reference here's the definition of the get_sale_price() API: https://github.com/woocommerce/woocommerce/blob/master/includes/abstracts/abstract-wc-product.php#L287

On a standard WooCommerce setup a product with no sale price will return an empty string, not NULL."

The two products we are having issues with are the only products that are classified as Simple Products in WooCommerce (all our other products are variable, bundle or component).
Does their explanation make sense to you and is it an issue being caused by the WOOCS plugin?

Hello

Try to add  in  functions.php add  this  code:

add_filter('woocs_raw_woocommerce_price', function($price){

if(NULL==$price){

$price="";

}

return $price;

});

Hi Pablo,

Having added the snippet/code you recommended to the functions.php the product we were looking at originally is still not reaching the feed, and it looks like get_sale_price() is still returning NULL for that product (see below screenshot):
https://www.dropbox.com/s/cz03t0mg6zs87zl/Screenshot%202020-08-26%20at%2013.08.30.png?dl=0

We attempted our own work around by applying the below code/snippet to the standard WooCommerce filters:

add_filter( 'woocommerce_product_get_sale_price', function ( $value, $product ) {
	if ( $value === null ) {
		return '';
	}

	return $value;
}, 99, 2 );

But that didn't work either which I believe implies the Currency Switcher is modifying the price after the above filter runs.

Please can you check that the original code/snippet you provided is correct and/or suggest an alternative solution?

Hello

Please  add wp-admin+FTP access - - https://c2n.me/43SC6rb.png ->https://c2n.me/42BAoj4.png

Added

Hello

This site - lifejacketskinprotection.com ?

Hi,

Yes that is our site (we also have lifejacketsunprotection.com which points to/redirects to lifejacketskinprotection.com).

Jono

Hello Jono

Try  in file - \wp-content\plugins\woocommerce-currency-switcher\classes\woocs_after_33.php  add code - https://c2n.me/48TFNpy.png

return  "";

Please can you supply the code as text (as opposed to a screenshot).

Thanks

Hello

this  code - https://c2n.me/48UHi8a.png