ukscotth Posted July 5, 2011 Share Posted July 5, 2011 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 More sharing options...
AyKay47 Posted July 5, 2011 Share Posted July 5, 2011 in your if statement you will need to use the comparison operator "==" $price2 == wpsc_the_product_price(); Edit: didnt scroll to see the actual if statement. Where is you $price2 variable coming from? Link to comment https://forums.phpfreaks.com/topic/241142-if-statement-not-working/#findComment-1238651 Share on other sites More sharing options...
ukscotth Posted July 5, 2011 Author Share Posted July 5, 2011 that part isnt in the if part though is it ? if you look I added == in the actual if part Link to comment https://forums.phpfreaks.com/topic/241142-if-statement-not-working/#findComment-1238655 Share on other sites More sharing options...
AyKay47 Posted July 5, 2011 Share Posted July 5, 2011 editted my previous post, please refer Link to comment https://forums.phpfreaks.com/topic/241142-if-statement-not-working/#findComment-1238656 Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2011 Share Posted July 5, 2011 What does var_dump($price2); show? And what exactly happens and what do you expect to happen? Link to comment https://forums.phpfreaks.com/topic/241142-if-statement-not-working/#findComment-1238670 Share on other sites More sharing options...
ukscotth Posted July 5, 2011 Author Share Posted July 5, 2011 Thanks alot for your help you 2 I tried the var_dump and it showed me that the string was 6 characters " $0.00" so it was the first blank character that was causing me the problems. Thanks again for your help. Problem solved Link to comment https://forums.phpfreaks.com/topic/241142-if-statement-not-working/#findComment-1238674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.