Import alternative regular price

Occasionally, some merchants will provide the "sale price" in the regular price field and put the regular price in another unknown field. This tutorial explains how to use an alternative field for the regular price so that the product appears to be "on sale" in your store.

Important!

These changes will only take effect after you have updated your Product Sets. You will not notice any changes on your site until your Product Sets have updated.

1

Identify the field which contains the regular price

First you will need to identify the alternative field you want to use in place of the default finalprice field. You can see all of the available fields for a product by clicking the product's name and then viewing the list of fields. In the screenshot below, this merchant has another field named recommendedretailprice which contains the actual "regular price".

An example of an alternative regular price field.
2

Create a custom plugin

If you haven't done so already, create a custom plugin.

3

Add custom code

Add the following code to your custom plugin file.

/**
 * Use an alternative field for the regular price.
 */
add_filter( 'dfrpswc_filter_postmeta_array', 'mycode_alternative_price_fields', 20, 5 );
function mycode_alternative_price_fields( $meta, $post, $product, $set, $action ) {

	$reg_price = false;

	// An array of alternative "regular price" fields.
	$regular_price_fields = array(
		'recommendedretailprice', // Use the 'recommendedretailprice' field if it exists.
		'rrpprice',               // Use the 'rrpprice' field if it exists.
	);

	// Loop through array to see if one of the keys exists for this product.
	foreach ( $regular_price_fields as $regular_price_field ) {
		if ( isset( $product[ $regular_price_field ] ) ) {
			$reg_price = $product[ $regular_price_field ];
			break;
		}
	}

	// If we have an alternative regular price, use it.
	if ( $reg_price ) {

		$meta['_regular_price'] = dfrps_int_to_price( $reg_price );
		$meta['_price']         = dfrps_int_to_price( $reg_price );

		// Handle sale price.
		if ( isset( $product['finalprice'] ) ) {

			$meta['_sale_price'] = dfrps_int_to_price( $product['finalprice'] );
			$meta['_price']      = dfrps_int_to_price( $product['finalprice'] );

			$meta['_dfrps_salediscount'] = ( ( ( $meta['_price'] - $meta['_sale_price'] ) / $meta['_price'] ) * 100 );
		}
	}

	return $meta;
}
	
4

Add your targetted image fields

Add to or modify the $regular_price_fields array to target fewer, more or different regular price fields. (line #11 - #12).

5

Save

Save your custom plugin file.

6

Add new Product Sets

These changes will only take effect after a Product Set is created or updated.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us