WP E-Commerce Custom Fields used in Conditional Statements

WP E-Commerce Custom Fields plugin enables custom meta fields to be added to all the products edit page.

Install the plugin from here:

https://wordpress.org/plugins/wp-e-commerce-custom-fields/

Once installed these custom fields are defined under the Products >> Attributes menu.
Create the attribute then assign values in the individual product admin pages.

To show the value of the field in the products page or single products page use the following in the template page for the view in question:

 wpsc_the_custom_fields( 'slug=YOUR_SLUG_GOES_HERE' );

This echoes the field value to the screen so can’t be used in a conditional such as:

//This wont work
if( wpsc_the_custom_fields( 'slug=YOUR_SLUG_GOES_HERE' ) == "Wholesale"){
echo "Wholesale product";
}

To be able to apply conditional tests to the custom field value we need to capture the buffer and assign it to a variable as follows:

ob_start();
wpsc_the_custom_fields( 'slug=wholesale-product' );
$output = ob_get_contents();
ob_end_clean();

Now $output holds the string that was returned by wpsc_the_custom_fields() function and we can apply conditional tests to  it.

For example, a variable $show is used to determine whether a product is visible on the products page based on whether it is a wholesale product or not.

$show = ( $output == 'wholesale' ) ? 0 : 1;

 if ($show == 1){ 
// show the product here
}

Clearly this process must occur within the product loop.