i have this function, which i want to use to feed a constantly changing price to the function at the bottom. can anyone tell me how to do this?
[php]
function feed_price() {
$usd = file_get_contents(‘https://www.bitstamp.net/api/ticker/’);
$expl = explode (’"’,$usd);
$usd = $expl[27];
$exchangerate = file_get_contents(‘http://www.google.com/ig/calculator?hl=en&q=1usd=?zar’);
$expl2 = explode (’"’,$exchangerate);
$exchangerate = $expl2[3];
$exchangerate = substr($exchangerate, 0, 5);
$salesprice = $usd * $exchangerate;
$salesprice = round($salesprice+($salesprice/16),2);
return $salesprice;
}
[/php]
[php]
function wpsc_the_product_price( $no_decimals = false, $only_normal_price = false, $product_id = 0 ) {
global $wpsc_query, $wpsc_variations, $wpdb;
if ( ! $product_id )
$product_id = get_the_ID();
if ( wpsc_product_has_variations( $product_id ) ) {
$from_text = __( ' from %s', 'wpsc' );
$from_text = apply_filters( 'wpsc_product_variation_text', $from_text );
$output = wpsc_product_variation_price_from( $product_id, array(
'from_text' => $from_text,
'only_normal_price' => $only_normal_price
) );
} else {
$price = $full_price = get_post_meta( $product_id, '_wpsc_price', true );
if ( ! $only_normal_price ) {
$special_price = get_post_meta( $product_id, '_wpsc_special_price', true );
if ( ( $full_price > $special_price ) && ( $special_price > 0 ) )
$price = $special_price;
}
if ( $no_decimals == true )
$price = array_shift( explode( ".", $price ) );
$price = apply_filters( 'wpsc_do_convert_price', $price, $product_id );
$args = array(
'display_as_html' => false,
'display_decimal_point' => ! $no_decimals
);
$output = wpsc_currency_display( $price, $args );
}
return $output;
}
function wpsc_calculate_price( $product_id, $variations = false, $special = true ) {
global $wpdb;
$p_id = $product_id;
if ( ! empty( $variations ) )
$product_id = wpsc_get_child_object_in_terms( $product_id, $variations, ‘wpsc-variation’ );
elseif ( !$product_id )
$product_id = get_the_ID();
if( ! $product_id && ! empty( $variations ) ){
$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 );
}
$price = apply_filters( 'wpsc_price', $price, $product_id );
return $price;
}
[/php]