NO BUG: {echo} function echos the literal echo statement when argument contains '$'

I have a PHP function, which is properly signed. It returns the result of a simple calculation.

In my woocommerce product query loop I am calling this function via {echo} and passing a string (the product price), in a basic text element, like this:

{echo:get_retail_price({woo_product_price})}

The problem is that on the front end, this is rendered as {echo:get_retail_price({woo_product_price})} (verbatim).

I tried replacing the nested dynamic data {woo_product_price} with the same value used for the first product in the loop: ‘$100.00’. On the front end it appeared as {echo:get_retail_price(‘$100.00’)}.

Then I tried removing the $ symbol, and it worked: {echo:get_retail_price(‘100.00’)}.

The bug then is that the echo function doesn’t seem to work if a parameter contains a dollar sign. Is there any workaround for this?

Can you share the code of get_retail_price()?

Hi @ainom ,

Please may I know if you have whitelisted the get_retail_price function?
Did you enable Code execution?

Regards,
Jenn

Sure
this isn’t the final code, but what I have currently to troubleshoot:

function get_retail_price ($wholesale) {    
    return "Output " . $wholesale;
}

Yes, code execution is enabled (other functions work fine) and this function has been whitelisted.

I don’t think it would work at all even without the $ symbol if it wasn’t whitelisted, correct?

I’m not sure you can do a nested dynamic tag here, regardless of the dollar sign.
But even if you can, the {woo_product_price} variable apparently returns HTML, not just the number with a dollar sign. Chances are whatever it’s returning can’t be sent to the function as-is.
In your case, the plain number would be {woo_product_regular_price:value}. But again, not sure if you can embed that into the echo function.

Another thing to try is to surround the inner tag with its own quote, to encapsulate the string, like echo:func( ’ {woo
} ’ )
Again I’m not sure if adding the single quotes will help at all.

Just a few ideas to check out!

2 Likes

Just tried what @vigilante wrote above and it works.

{echo:get_retail_price({woo_product_price:value})}

It is possible to have dynamic data as function arguments.

1 Like

That’s right, by default the {woo_product_price} returning HTML strings.

You can try

{echo:get_retail_price('{woo_product_price}')}

or

{echo:get_retail_price('{woo_product_price:plain}')} if you need the symbol

doesn’t work.

Boom! Adding “:value” works! Thank you so much!

How did you know that {woo_product_price} returns HTML? Is there some documentation somewhere that shows shat each dynamic tag returns and it’s format? Knowing this could have saved me so much time.

Neither of these work. Only
{echo:get_retail_price('{woo_product_price:value}')}
works.

From the Bricks academy WooCommerce Builder page.