Hi @thewks
As far as I know the only way to mark a product as “on sale” is to set a sale price that’s lower than the regular price. Does your feed have a sale price? If not, what exactly are you wanting to do with the price when “WITH_DISCOUNT” is set to 1?
Thread Starter
thewks
(@thewks)
Hello, thank you for fast reply. My feed does not have sale price.
I need, if is value WITH_DISCOUNT for example set to 1 – show sale badge. Is it possible?
Hi @thewks
I need, if is value WITH_DISCOUNT for example set to 1 – show sale badge. Is it possible?
You can only show the sale badge if you have a sale price lower than the regular price, so you’d have to use a custom PHP function for this: http://www.wpallimport.com/documentation/advanced/execute-php/.
The idea would be to use a custom function like this:
function my_return_price( $price, $with_discount, $field ) {
if ( $with_discount == 1 ) {
return ( $field == 'regular_price' ) ? number_format( $price * 1.1, 2 ) : $price;
} elseif ( $with_discount == 0 ) {
return ( $field == 'regular_price' ) ? number_format( $price, 2 ) : null;
} else {
return $price;
}
}
This is only an example, so you may need to adjust it, but the idea is to mark up the regular price by 10% in the case that “with discount” is 1. This function would be used in each price field like this:
[my_return_price( {price[1]}, {with_discount[1]}, "regular_price" )]
[my_return_price( {price[1]}, {with_discount[1]}, "sale_price" )]
Just make sure to change {price[1]} and {with_discount[1]} to the correct elements from your file.