The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] Code to output price? (10 posts)

  1. yalrighty
    Posted 3 years ago #

    Hi. I have woocommerce and have open graph protocol and Social SEO booster. But they do not generate a price open graph tag.

    I wish to generate the following:

    <meta property="og:price:amount" content="15.00" /> where 15.00 is the price of the product being viewed. This is so that I can have Pinterest Rich Pins.

    I have found the following codes looking thru the php files but neither seem to work for me?

    <?php echo $product->get_price_html(); ?>
    <?php echo get_woocommerce_single_product_price(); ?>

    It is probably something simple, but I am new to WP, Woocommerce, and not really a good php programmer yet.


  2. yalrighty
    Posted 3 years ago #

    Still no luck on my end. Getting frustrating lol I either cause a while screen of death or the tag doesn't show up. I hope someone can help me

  3. Roy Ho
    Posted 3 years ago #

    You need to globalize the variable on that page for you to access its methods.

    global $product;
  4. yalrighty
    Posted 3 years ago #

    ok so would it be like this?

    <?php global $product ?>


    <meta property="og:price:amount" content="<?php echo $product->get_price_html(); ?>" />

    Sorry I'm really not a php programmer as you can probably tell.

  5. yalrighty
    Posted 3 years ago #

    I tried what I put above and the meta tag generates but it is coming out like this when I go to view page source

    <meta property="og:price:amount" content="<span class="amount">$67.95</span>" />

    So I am almost there ... just need to change it so that it doesn't spit out the span tags ... I just need the price with no dollar sign

  6. yalrighty
    Posted 3 years ago #

    I got it with the following code

    <?php global $product ?>
    <meta property="og:price:amount" content="<?php echo $product->get_price(); ?>" />

    I put that in the content-single-product.php file and it works fine and generates the proper open graph tag. But how do I move it so that it appears between the <head></head> tags with the other open graph tags? I tried putting it in header.php but it caused white screen of death.

  7. Roy Ho
    Posted 3 years ago #

    If you're doing it in the header, I am not sure if product has been globalized yet...

    So the other thing you can do is use $post global and create a new product object like so:

    global $post;
    $product = get_product( $post->ID );
    echo $product->get_price();
  8. yalrighty
    Posted 3 years ago #

    Thank you so very very much!!!! That worked like a charm. I can't thank you enough I have been confused on this for 2 days now lol.

  9. Roy Ho
    Posted 3 years ago #

    Also you might want to add a conditional check as I don't think you want that to be outputed on every page...

    if ( is_product() ) {
    // do your code here

    This will make sure the page is on single product page...

  10. JS Morisset
    Posted 3 years ago #

    Have a look at NGFB Open Graph+ v6.6 coming out this week-end. ;-)


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.