• Resolved zoliandru

    (@zoliandru)


    Hello

    On a specific template in Astra Theme, I try to display the price of the current product.
    To do so, I put à PHP code in the functions.php file to create à shortcode.

    Error message when trying to save the publication : Update failed
    When trying to reload the page, or access it again from the dashboard; I got the lightgray screen with the critical error message.

    If I disable the code, save the page with the sort code in it, then reactivate the code in the function file, here is what happening :

    The dashboard, and the frontend are working fine, the shortcode works and display the price on the frontend, but the page in the backend where I put the shortcode is broken.

    Here is the php code I put in function.php :

    add_shortcode( 'avv-woo-price', function () {
        $product = wc_get_product(get_the_ID());
        $thePrice = $product->get_price_html();
        return $thePrice;
    } );

    Could you please help me find what I miss ?

    Thank you very much !

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Hi there,

    Let’s refactor and simplify just a little bit.

    add_shortcode( 'avv-woo-price', 'avv_display_my_product_price' );
    function avv_display_my_product_price() {
        $product_price = wc_get_product(get_the_ID());
        return $product_price;
    }

    Does that work in the backend?

    Kind regards,

    Thread Starter zoliandru

    (@zoliandru)

    Hello @conschneider

    Thank you for your fast reply !

    Your code does not break anything, but does not give me the price either.
    It returns everything on the product.

    So I tried to add the “get the price argument” like this :

    add_shortcode( 'avv-woo-price', 'avv_display_my_product_price' );
    function avv_display_my_product_price() {
        $product_price = wc_get_product(get_the_ID())->get_price_html();
        return $product_price;
    }

    But the problem stays : it works in the front end, but it breaks my backend page.

    Thread Starter zoliandru

    (@zoliandru)

    Hello @conschneider

    Any update and further help on this issue?

    Thanks in advance !

    Plugin Support Cara

    (@dcka)

    Hi, @zoliandru!

    Sorry for the delayed response here.

    Do you still need help with your code?

    If so, I’m going to leave this thread open for a bit to see if anyone is able to chime in to help you out.

    In case you haven’t seen this yet, you can check the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.`

    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    We’ve not seen any activity on this thread for a while, so I’m marking this thread as resolved.

    Hopefully, you were able to find a solution to your problem! If you have further questions, please feel free to open a new topic.

    Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP Shortcode to display the price works on frontend but breaks the editor’ is closed to new replies.