Manually create RoyalSlider {{variable}} error.

Vince's Avatar

Vince

06 Feb, 2019 08:02 PM

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);

  1. Support Staff 1 Posted by Dmitry Semenov on 06 Feb, 2019 10:20 PM

    Dmitry Semenov's Avatar

    Hello,

    The code seems to be correct, does it work for you when you try to return just string? For example {{my_product_price}}:

    function add_royalslider_product_price($m, $data, $options) {
    
        $m->addHelper('my_product_price', function() use ($data) {
            return "TEST PRICE";
        } );
    
    }
    add_filter('new_rs_slides_renderer_helper','add_royalslider_product_price', 10, 4);
    
  2. 2 Posted by Vince on 06 Feb, 2019 10:36 PM

    Vince's Avatar

    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.

  3. Support Staff 3 Posted by Dmitry Semenov on 07 Feb, 2019 06:57 AM

    Dmitry Semenov's Avatar

    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:

    function add_slider_variables($m, $data, $options) {
    
        $m->addHelper('my_product_price', function() use ($data) {
            return "TEST PRICE";
        } );
    
        $m->addHelper('my_product_id', function() use ($data) {
            return "TEST ID";
        } );
    
    }
    add_filter('new_rs_slides_renderer_helper','add_slider_variables', 10, 4);
    
  4. 4 Posted by Vince on 07 Feb, 2019 10:55 AM

    Vince's Avatar

    This works with the strings, but as soon as i add return $_product->get_price(); and return $_product->get_id(); it crashes.

    What am I missing?

    EDIT: Thank You Dmitry ! It works

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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