Google Product Feed – Template tags

The Google Product Feed plugin allows you to enter additional product data against products. Predominantly this is used for sending to Google in the product feed, however you may also want to display that same information on your product pages.

The plugin includes a number of template tag functions that can be used in your theme templates to output individual fields. There are examples of the various template functions below.

Note: This article requires version 7.2.1 or higher of the Google Product Feed plugin

Output a field without a label ↑ Back to top

This example shows how to output the value of the “GTIN” field for a product.

woocommerce_gpf_show_element( 'gtin' );

This will product output like this:

valueofgtinhere

There’s no styling applied to this output by default, but there are CSS classes added so you can select the fields and style them how you want. This example produces the following markup:

<div class="woocommerce-gpf-element">
    <span class="woocommerce-gpf-element-value">valueofgtinhere</span>
</div>

If the field is a multi-value field with multiple values set, then the values will appear as a comma separated list, e.g.

value1, value2, value 3

Note: The template tags assumes that it is being used within the loop. If used outside of the loop, you should pass in the WordPress post object as the second parameter, e.g.

woocommerce_gpf_show_element( 'gtin', $post );

Output a field with a label ↑ Back to top

This example shows how to output the value of the “GTIN” field for a product, together with a field label.

woocommerce_gpf_show_element_with_label( 'gtin' );

This will product output like this:

Global Trade Item Number (GTIN): valueofgtinhere

There’s no styling applied to this output by default, but there are CSS classes added so you can select the fields and style them how you want. This example produces the following markup:

<div class="woocommerce-gpf-element">
    <span class="woocommerce-gpf-element-label">Global Trade Item Number (GTIN)</span>: 
    <span class="woocommerce-gpf-element-value">valueofgtinhere</span>
</div>

If the field is a multi-value field with multiple values set, then the values will appear as a comma separated list, and the label will only appear once, e.g.

Global Trade Item Number (GTIN): value1, value2, value 3

Note: The template tags assumes that it is being used within the loop. If used outside of the loop, you should pass in the WordPress post object as the second parameter, e.g.

woocommerce_gpf_show_element_with_label( 'gtin', $post );

Retrieve field values ↑ Back to top

If you just want to retrieve the value(s) of a field to control the output yourself, you can do so with the following function:

woocommerce_gpf_get_element_values( 'gtin' );

This will return an array of the values for that field for the current post, e.g.

Array
(
    [0] => mygtin
    [1] => othergtin
)

Questions & Feedback ↑ Back to top

Have a question before you buy? Please fill out this pre-sales form.

Already purchased and need some assistance? Open a support ticket via the Help Desk.

WooCommerce - the most customizable eCommerce platform for building your online business.

Back to the top