Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.