Modifying the global product template

The plugin already comes with sensible defaults for the product template. It will simply use the WooCommerce product title and the product description, and automatically truncates and formats them to fit within the limitations of Google Business Profile. 

However, in certain situations you may want to tweak the template to suit your requirements. This can be done in the Product template section of the plugin settings:

How the placeholder tags work

The plugin exposes the entire WC_Product class for the current product (and their extensions such as WC_Product_Simple, WC_Product_Variable, WC_Product_External), through the "Mustache" template engine. This allows for extreme flexibility in the product template. 

The tags in the template are replaced by their corresponding value in the resulting product on your Google Business Profile listing. For example the {{wc_product.get_description}} tag that you see in the default template automatically gets replaced with the WooCommerce product description.

Otherwise the Title and Description fields are just plain text fields, and any other text you write in there will show up literally in your product descriptions. 

Take the following description template for example:

<qoute>Check out my newest product: {{wc_product.get_title}}
	
Now on sale for only ${{wc_product.get_price}} when picking up in the store</qoute>

The resulting product on your Google Business Profile listing will look something like this:

Check out my newest product: Example product title

Now on sale for only $123.45 when picking up in the store

Available placeholder tags

Here are some of the most useful tags that are available:

  • {{wc_product.get_title}}
  • {{wc_product.get_description}}
  • {{wc_product.get_short_description}}
  • {{wc_product.get_price}} - The current price of the product, taking sale price into account
  • {{wc_product.get_regular_price}} - The price of the product when it isn't on sale
  • {{wc_product.get_price_excluding_tax}}
  • {{wc_product.get_min_purchase_quantity}}
  • {{wc_product.get_length}} - The physical length of the product (get_height and get_width are likewise also available)

For more available tags, check the WC_Product documentation and look for the functions prefixed with "get_". They can all be used by using the following format: {{wc_product.get_<name_of_the_function>}}

Advanced usage - Conditions

The template engine allows you to create "conditions" as well. Lets say you want to show whether a product is in stock. We can use the "is_in_stock" function from the WC_Product class. 

Here is the title of the product: {{wc_product.get_title}}

{{#wc_product.is_in_stock}}
	The product is in stock!!
{{/wc_product.is_in_stock}}

The "The product is in stock!!" text will only be shown if the product is in stock.

Advanced usage - Lists

Lets say you want to display the product attributes in your product description. In that case we can use the "get_attributes" function.

Here are the attributes of my product:

{{#wc_product.get_attributes}}
	{{.}}
{{/wc_product.get_attributes}}

As you can see the template has a lot of flexibility, and we've just scratched the surface of what is possible. It may seem a bit daunting and technical even! Don't hesitate to reach out if you need help customizing your template.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us