1. PROMO Get 60% OFF Lifetime Pro Membership & access all our Pro Divi Extensions, Divi Layouts, Divi AI Generator, Divi Block, etc.VIEW PRICING
Dismiss Notice
UPDATE Custom Color Scheme + Premade Divi Layouts - A perfect combination to boost productivity. New 'Gadget Repair' layout added.Try our Custom Color Layouts
BEST Divi Block - A revolutionary drag & drop tool to easily mix & match 960+ premade blocks (Light & Dark) to kick start your Divi site design. Special module designs are included as well.
Learn More About Divi BlockFree Version ~ 340+ Free Blocks

Adding a Price

Discussion in 'Free Divi Community Forum' started by chriz122, Jul 3, 2024.

  1. chriz122

    chriz122 New Member

    Hi, i have ACF installed and try to get the function to get a Price shown under the Divi Blog Module Title.
    I have the ACF Field "price" and this code into the blog.php in my child theme but its not working
    if ( function_exists('get_field') && get_field('price') ) {
        $price = get_field('price');
        <div class="custom-price">
            Preis: <?php echo esc_html($price); ?>
    <?php } ?>

    thank you <3
    1. PRO MEMBER PERKS Beautifully crafted custom colored 'Industrial' Divi layout for all Pro members:View Demo
  2. Divi Booster

    Divi Booster Divi Expert

    Hey Chriz122,

    Does the text "Preis:" show up?

    If so, then one possible issue I think could occur is with the get_field() call. By default get_field() returns the field value for the current page / post. In the case of a page containing the blog module this might cause it to return the price value set on the page itself (which is probably not set), rather than picking it up from the posts listed in the blog module. ACF might pick up the correct posts from the blog module loop - I'm not sure off the top of my head - but if not you may need to pass the post id as the second parameter to get_field() - something like this:

    $price = get_field('price', $post_id);

    (you'd need to set $post_id in your code).