Forum

Support is provided free and on a “best endeavours” basis. This is usually daylight hours, UK time, Monday to Friday. At the time of this screen being refreshed it was Wednesday 6:30pm in the UK.

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1] 2
AuthorTopic: php function call problem
nedbenj
Newbie
Posts: 3
Permalink
Post php function call problem
on: June 11, 2012, 20:56
Quote

Hi there,

First of all, thanks for making this great plugin! Secondly, I wonder if you could help me - I can't seem to get the php function call to work. For an example, if I add

<?php get_conversion('number=145&from=eur&to=usd'); ?>

below:

<?php the_content(); ?>

in page.php, nothing displays. Am I misunderstanding how it works? It works okay if I use a the shortcode in a post or page.

Thanks for your help.

David-
Artiss
Administrator
Posts: 553
Permalink
Post Re: php function call problem
on: June 12, 2012, 07:40
Quote

That's my fault - poor instructions!

get_conversion will return the result but not output. So you'd need to put...

<?php echo get_conversion('number=145&from=eur&to=usd'); ?>

David.

nedbenj
Newbie
Posts: 3
Permalink
Post Re: php function call problem
on: June 12, 2012, 19:08
Quote

Hi David,

Thanks very much for that. I've only just started learning php, so it's all very new to me. If you don't mind me asking, how would I go about passing the 'number' variable, which is returned from another function, to the get_conversion function?

This is the function which returns the number I need to use:

function listing_price() {
	global $post;
	$price_meta = get_post_meta(get_the_ID(), '_ct_price', true);
	$price_meta= preg_replace('/[\$,]/', '', $price_meta);
	echo  number_format($price_meta, 0, '.', ',');
}

Regards,
Ned

David-
Artiss
Administrator
Posts: 553
Permalink
Post Re: php function call problem
on: June 12, 2012, 20:47
Quote

You would probably need to add the following...

<?php echo get_conversion('number='.$price_meta.'&from=eur&to=usd'); ?>

David.

nedbenj
Newbie
Posts: 3
Permalink
Post Re: php function call problem
on: June 12, 2012, 23:48
Quote

Thanks very much, I've got it working now.

decors
Newbie
Posts: 4
Permalink
Post Re: php function call problem
on: July 14, 2012, 14:32
Quote

Hi David, would really appreciate it if you could help. I am using marketpress plugin and the price displayed on product page is called by a function code mp_product_price(), the script on the product page is <?php mp_product_price(); ?> and nothing else, the full code for this function is residing in another file, how can I modify your plugin's function call so that it will take the value returned by mp_product_price() function?
Here's the code from the plugin's template_function page:
function mp_product_price( $echo = true, $post_id = NULL, $label = true ) {
global $id, $mp;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$label = ($label === true) ? __(' ', 'mp') : $label;
$settings = get_option('mp_settings');
$meta = get_post_custom($post_id);
//unserialize
foreach ($meta as $key => $val) {
$meta[$key] = maybe_unserialize($val[0]);
if (!is_array($meta[$key]) && $key != "mp_is_sale" && $key != "mp_track_inventory" && $key != "mp_product_link" && $key != "mp_file" && $key != "mp_price_sort")
$meta[$key] = array($meta[$key]);
}
if ((is_array($meta["mp_price"]) && count($meta["mp_price"]) == 1) || !empty($meta["mp_file"])) {
if ($meta["mp_is_sale"]) {
$price = '<span class="mp_special_price"><del class="mp_old_price">'.$mp->format_currency('', $meta["mp_price"][0]).'</del> ';
$price .= '<span class="mp_current_price" style="color:red">'.$mp->format_currency('', $meta["mp_sale_price"][0]).'</span></span>';
} else {
$price = '<span class="mp_normal_price"><span class="mp_current_price">'.$mp->format_currency('', $meta["mp_price"][0]).'</span></span>';
}
} else {
return '';
}
$price = apply_filters( 'mp_product_price_tag', '<span class="mp_product_price">' . $label . $price . '</span>', $post_id, $label );
if ($echo)
echo $price;
else
return $price;
}
Finger crossing you could help. Best regards,
Cors

David-
Artiss
Administrator
Posts: 553
Permalink
Post Re: php function call problem
on: July 15, 2012, 09:22
Quote

If you need to be able to do this via the shortcode then that's a program change. However, if you want to do this via PHP function call then that you can do yourself.
Something like this should do it - basically you're passing the result of the mp_product_price function back into the currency converter call. Obviously, you'd need to change the "to" and "from" currencies.

<?php get_conversion( 'number='.mp_product_price().'&from=gbp&to=usd' ); ?>

Is that what you were after?
David.

decors
Newbie
Posts: 4
Permalink
Post Re: php function call problem
on: July 15, 2012, 10:17
Quote

Thanks David for replying so quickly, the mp_product_price() returned price together with it's currency, for example, USD 450, and if it's on sale, it would returned a GBP 450 GBP 100, so with your code (which I've tried already before I posted for help), returned exactly "GBP 450". I was thinking about trimming the returned string but I don't know where to start, The format of the price returned has a space in between, i.e. GBP[space]xxx, and take only the latter price by filtering out the strike-through fonts..

Just so you know I didn't post for help with empty hands or not trying to solve it myself first - I am not a coder, I read those codes and tried to make sense out of it, and these are my finders, I hope you can help..

Sincerely,
Cors

David-
Artiss
Administrator
Posts: 553
Permalink
Post Re: php function call problem
on: July 15, 2012, 14:16
Quote

Assuming the currency is returns is the "from" for my currency converter, the following should work...

<?php
$mp_price = mp_product_price();
$currency = substr( $mp_price, 0, strpos( $mp_price, ' ' ) -1 );
$number = substr( $mp_price, strpos( $mp_price, ' ' ) + 1 );
echo get_conversion( 'number=' . $number . '&from=' . $currency . '&to=usd' );
?>

It uses the space between the currency and the number to extract the 2 separately and then calls my conversion passing them on.

David.

decors
Newbie
Posts: 4
Permalink
Post Re: php function call problem
on: July 15, 2012, 16:04
Quote

LOVE the "currency" is the "from" part! But I think mp_product_price() itself is echo-ing the result (both before and after sale price, the former are strike-throughs), putting your suggested code into the page gave following result:

RM 450.00Artiss Currency Converter Error: No number supplied for conversion

'RM' is the currency I've set for my store, by using your code the from's currency shouldn't matters anymore (thanks for this, again), but I think the RM 450 is returned by the mp_product_price() itself, I never need to echo it out, just place mp_product_price() that's all..

Thanks and I hope you could give me some more hints?

Quote from David Artiss on July 15, 2012, 14:16
Assuming the currency is returns is the "from" for my currency converter, the following should work...

<?php
$mp_price = mp_product_price();
$currency = substr( $mp_price, 0, strpos( $mp_price, ' ' ) -1 );
$number = substr( $mp_price, strpos( $mp_price, ' ' ) + 1 );
echo get_conversion( 'number=' . $number . '&from=' . $currency . '&to=usd' );
?>

It uses the space between the currency and the number to extract the 2 separately and then calls my conversion passing them on.
David.

Pages: [1] 2
Mingle Forum by cartpauj
Version: 1.0.34 ; Page loaded in: 0.052 seconds.
Loading Facebook Comments ...

2 Thoughts on “Forum

  1. Pingback: Artiss YouTube Embed » WordPress AddOns

  2. Pingback: Artiss YouTube Embed | Best Plugins - wordpress – widgets – plugin

2 Trackbacks for "Forum"
  1. [...] Although this document contains a lot of information more is available from a series of linked pages, plus as much information as possible is provided on the various administration pages. Whilst on the administration pages, click on the “Help” button in the top right for some useful tips and links. If anything isn’t covered and you’re unsure of what it does please ask on the forum. [...]

  2. Artiss YouTube Embed | Best Plugins - wordpress – widgets – plugin says:

    [...] Although this document contains a lot of information more is available from a series of linked pages, plus as much information as possible is provided on the various administration pages. Whilst on the administration pages, click on the “Help” button in the top right for some useful tips and links. If anything isn’t covered and you’re unsure of what it does please ask on the forum. [...]

Top
%d bloggers like this: