Jump to content

if statement not working


ukscotth

Recommended Posts

Hi,

 

Im trying to use an IF ststement in a piece of code but it doesnt seem to be working, please can you help.

 

Heres the IF ststement :

 

$price2 = wpsc_the_product_price();
										if ($price2 == "$0.00"){echo "Request Quote";}

 

and heres the wpsc_the_product_price() function :

 

function wpsc_the_product_price( $no_decimals = false ) {
global $wpsc_query, $wpsc_variations, $wpdb;
if ( isset($wpsc_variations->first_variations) && count( $wpsc_variations->first_variations ) > 0 ) {
	//select the variation ID with lowest price
	$output = wpsc_product_variation_price_available(get_the_ID());
	$from = ' from ';
} else {
	$product_id = get_the_ID();
	$from = '';
	$full_price = get_post_meta( $product_id, '_wpsc_price', true );
	$special_price = get_post_meta( $product_id, '_wpsc_special_price', true );
	$price = $full_price;

	if ( ($full_price > $special_price) && ($special_price > 0) )
		$price = $special_price;

	if ( $no_decimals == true )
		$price = array_shift( explode( ".", $price ) );

	$args = array(
		'display_as_html' => false,
		'display_decimal_point' => !$no_decimals
	);	
	$output = wpsc_currency_display( $price,$args );
}


//if product has variations - add 'from'
$from = apply_filters('wpsc_product_variation_text',$from);
if ( isset($wpsc_variations->first_variations) && count( $wpsc_variations->first_variations ) > 0 && !empty($from))
	$output = sprintf(__(' from %s', 'wpsc'), $output);

return $output;
}

function wpsc_calculate_price( $product_id, $variations = null, $special = true ) {
global $wpdb;
$p_id = $product_id;
if ( count( $variations ) > 0 ){
	if(!isset($variations) || is_array($variations) && in_array(0,$variations,true)) return;
	$product_id = wpsc_get_child_object_in_terms( $product_id, $variations, 'wpsc-variation' );
}else if ( !$product_id )
	$product_id = get_the_ID();

if( !$product_id && count( $variations ) > 0){
	$product_ids = wpsc_get_child_object_in_select_terms( $p_id, $variations, 'wpsc_variation' );
	$sql = "SELECT `post_id` FROM ".$wpdb->postmeta." WHERE `meta_key` = '_wpsc_stock' AND `meta_value` != '0' AND `post_id` IN (".implode(',' , $product_ids).")";
	$stock_available = $wpdb->get_col($sql);
	$sql = "SELECT `post_id` FROM ".$wpdb->postmeta." WHERE `meta_key` = '_wpsc_price' AND `post_id` IN (".implode(',',$stock_available).") ORDER BY `meta_value` ASC LIMIT 1";
	$product_id = $wpdb->get_var($sql);
}

if ( $special ) {
	$full_price = get_post_meta( $product_id, '_wpsc_price', true );
	$special_price = get_post_meta( $product_id, '_wpsc_special_price', true );

	$price = $full_price;
	if ( ($full_price > $special_price) && ($special_price > 0) ) {
		$price = $special_price;
	}
} else {
	$price = get_post_meta( $product_id, '_wpsc_price', true );
}

return $price;
}

 

If I echo wpsc_the_product_price() it comes up as $0.00 but when I try and use IF with it it doesnt seem to work.

 

Please shelp its driving me mad :(

Link to comment
https://forums.phpfreaks.com/topic/241142-if-statement-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.