php - How would you combine this wordpress shortcode template code?

566

I am using a plugin that is generating my price value and pulling it from an array:

<?php echo __('Price: ', 'event_espresso'); ?></span> <?php echo 
$org_options['currency_symbol'].$event->event_cost; ?>

I want to convert this generated value into my visitors own currency depending on the country their in with the plugin 'Worldcurrency'

However you have to input a value in the short code like so:

[worldcurrency curr="EUR" value="25"]
in united states will show:
(~30$ USD)

Now I know how to use a shortcode in a template php file but I don't know if its possible to insert my array value and currency symbol into this shortcode. Rather than usingvalue="25" i need to use:

value="<?php echo $org_options['currency_symbol'].$event->event_cost; ?>"

Is this possible?

370

Answer

Solution:

I'm not sure whether it's possible to use PHP code inline in a shortcode - and I suspect not, however an easy enough way to implement this would be to write a shortcode of your own that then called the other shortcode.

Your shortcode would generate the text you want (eg '[worldcurrency curr="EUR" value="25"]'), and call "do_shortcode($content)" which would then cause the other plugin to do the currency lookup for you.

You could put this in a plugin file and it would probably amount to less than 15 lines of code.

The other option is to modify the currency conversion plugin you are using to produce the output you want.

People are also looking for solutions to the problem: phpexcel - PHP Excel image change size

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.