WooCommerce & og:price

pxoxrxn

Supreme Member
Joined
Dec 21, 2011
Messages
1,398
Reaction score
2,084
Does anyone know how I can get these tags into my WooCommerce product page?

<meta property="og:price:amount" content="1.00" />
<meta property="og:price:currency" content="USD" />

I have the following from the 'All in One SEO' social addon:
<meta property="og:title" content="Product title" /><meta property="og:type" content="product" />
<meta property="og:url" content="product URL" />
<meta property="og:image" content="Product featured image" />
<meta property="og:site_name" content="Site title" />
<meta property="og:description"" />

But for some reason they left out price and currency. I would prefer to add it straight to the header.php because I don't want to install more SEO plugins that will conflict with All in One SEO.
Thanks
 
Create a new, empty, plugin (it won't affect performance in a visible way because it is really simple and small piece of code) and put this in it:

function rioda_print_fb_price()
{
if( is_product() )
{
$product = new WC_Product( get_the_ID() );
echo '<meta property="og:price:amount" content="'.$product->price.'" />
<meta property="og:price:currency" content="'.get_woocommerce_currency().'" /> ';
}
}

add_action( 'wp_head', 'rioda_print_fb_price' );


It will print the informations only on the woocommerce products pages.
I did this on the fly, so it may require some tuning if your site has some complexities, but it should be enough to cover most cases (tested and it works).

If you need more help or customizations shoot me a PM, I love to work with wordpress (creating and troubleshooting plugins and themes).
 
Try searching for a plugin, most likely if you need to do it, lots of others have already
 
Back
Top