I want to show either the WooCommerce Price OR the WooCommerce Bookings Price in a Divi module


I am using WooCommerce combined with WooCommerce Bookings.

We have two types of product, bookable products and nonbookable products. I would like to show the price for the product on the page within a Divi module. We are using Divi to completely style the page of the Divi product so I cannot use an override like I ususally would.

Is there a way to add some PHP code to the functions file then call it as a shortcode in a Divi module?

I tried adding this code to my functions.php within my child theme but when I call it it errors and won’t save the page.


function woo_price_and_bookings_price ($atts)
    global $product;
    $product_id = $product->get_id();
    echo '<h1>The price is: ' . $product->get_price_html() . '</h1>';
add_shortcode( 'price_and_bookings_price', 'woo_price_and_bookings_price' );

shortcode I am calling


The price does not appear, but my text does. However my text appears at the very top of the page and not in the position I have assigned it in Divi. The page also errors on save and seems to automatically open a new page whenever I do this.

The page that opens contains nothing except my code (twice for some reason):

The price is:

What am I doing wrong and is this the right way to approach this task? I need to use Divi as I have inherited the site and we are not using traditional product pages.

Eoin 3 years 2020-07-04T09:10:32-05:00 0 Answers 66 views 0

Leave an answer