Manually create RoyalSlider {{variable}} error.
I want to create a variabele for both my_product_price and my_product_id. I tried the following code but it doesn't work. What am i doing wrong?
// Function for slider Price
function add_royalslider_product_price($m, $data, $options) {
$m->addHelper('my_product_price', function() use ($data) {
$_product = wc_get_product( $data->ID );
return $_product->get_price();
} );
}
add_filter('new_rs_slides_renderer_helper','add_royalslider_product_price', 10, 4);
// Function for slider ID
function add_royalslider_product_id($m, $data, $options) {
$m->addHelper('my_product_id', function() use ($data) {
$_product = wc_get_product( $data->ID );
return $_product->get_id();
} );
}
add_filter('new_rs_slides_renderer_helper','add_royalslider_product_id', 10, 4);
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Dmitry Semenov on 06 Feb, 2019 10:20 PM
Hello,
The code seems to be correct, does it work for you when you try to return just string? For example
{{my_product_price}}
:2 Posted by Vince on 06 Feb, 2019 10:36 PM
Hi Dmitry,
It doesn't work when I try to return a string. It doesn't show the page content at all.
When I only use the first part (slider price) it works. But as soon as I add the Id part it stops working.
Support Staff 3 Posted by Dmitry Semenov on 07 Feb, 2019 06:57 AM
Make sure that you don't have syntax errors such as extra symbols between lines. Also, you can add multiple helpers in one filter like this:
4 Posted by Vince on 07 Feb, 2019 10:55 AM
This works with the strings, but as soon as i add
return $_product->get_price();
andreturn $_product->get_id();
it crashes.What am I missing?
EDIT: Thank You Dmitry ! It works