Custom Template 2 (XML)

Custom Template 2 is one of the premium functionality of our plugin. Using Custom Template 2, it’s possible to make any type of  XML Product Feed for WooCommerce. 

All patterns must be enclosed in curly brackets. In patterns, you can use codes of attributes, formatters, links to parent products, base PHP functions and calculations.

The base pattern shema  {attribute_code, [ formatter 1 ], [ formatter 2 ], … }

Default Attribute Patterns:

  • Product ID {id} – ID of the product
  • Parent Id {item_group_id} – Id of the parent product of variations
  • SKU {sku} – an identifier of the product
  • Parent SKU {parent_sku} – an identifier of the product
  • Product Name {title} – a name of the product
  • Description {description} – a description of the product
  • Short Description {short_description} – a short description of the product
  • Product Local Category {product_type} – Category hierarchy of the product
  • Product URL {link} – URL of the product
  • Product Condition {condition} – Condition of the product. Default value “New”
  • Availability {availability} – Availability status of the product. Possible values :
    • In Stock
    • Out Of Stock
  • Quantity {quantity} – Quantity of the product
  • Regular Price {price} -Regular price of the product (without discounts)
  • Sale Price {sale_price} – Sale price of the product
  • Price With Tax {price_with_tax} – Price including tax 
  • Sale Start Date {sale_price_sdate} – Start date of sale price
  • Sale End Date {sale_price_edate} – End date of sale price
  • Weight {weight} –  Weight of the product
  • width {width} – Width of the product
  • height {height} – Height Of the Products
  • length {length} – Length of the product
  • Product Type {type} – Type of the Product. Possible Values:
    • simple
    • variable
    • grouped
    • external
    • virtual
    • downloadable
  • Variation Type {variation_type} – Variation status of the product. Possible values:
    • parent
    • child
    • simple
  • Total Rating {rating_total} – Total rating of the product
  • Average Rating {rating_average} – Average Rating of the product
  • Tags {tags} – Tags of the product. 
  • Image {image} – a direct URL to base image of the product
  • Featured Image {feature_image} – a direct URL to thumbnail image of the product
  • Image 1 {image_1}, Image 2 {image_2}, Image 3 {image_3}, Image 4 {image_4}, Image 5 {image_5}, Image 6 {image_6} , Image 7 {image_7} , Image 8 {image_8} , Image 9 {image_9} , Image 10 {image_10} – a direct url to gallery images of the product
  • Visibility {visibility} – a visibility of the product. Possible Values:
    • public
    • password
    • private
  • Also, it’s possible to use other WooCommerce attributes, Dynamic Attributes, and Category Mapping Attributes. You can get the attributes codes by selecting the Product Attributes Dropdown at the bottom of the Custom Template 2  Feed Config section.

Only Parent product values:

You can use suffix  |only_parent ({link|only_parent}{image|only_parent} etc), if you need to return only value of the parent product.
If the plugin can’t find the value of the parent product attribute, all its child products will also have no values, even if the child has values of this attribute.

Parent value, if parent value is not empty:

You can use suffix  | parent  ({image|parent}{link|parent} etc), for return parent value, if child product value is empty.

Parent value, if child value is empty:

You can use suffix   |parent_if_empty ({image|parent_if_empty}{link|parent_if_empty} etc), for return parent value, if child product value is empty.

Output Formatters: 

Every formatter should be enclosed with the third bracket and should have space before every parameter. For Example:

        {name, [substr 0 80], [...]}
Formatter Description Schema Example
strip_tags Remove all HTML tags {attribute_code, [strip_tags]} {description, [strip_tags]}




htmlentities Convert all applicable characters to HTML entities {attribute_code, [htmlentities]} {description, [htmlentities]}
htmlspecialchars Convert special characters to HTML entities {attribute_code, [htmlspecialchars]} {description, [htmlspecialchars]}
clear Remove all non-utf-8 characters from the string {attribute_code, [strip_tags]} {description, [clear]}
substr Truncate the string {attribute_code, [substr from to]} {name, [substr 0 80], […]}
str_replace
Replace any string {attribute_code, [str_replace => from => to]} {description, [ str_replace => ABC => XYZ], […]}
ucwords
Uppercase the first character of each word in the string {attribute_code, [ucwords]} {name, [ucwords]}
ucfirst
Make the string’s first character uppercase {attribute_code, [ucfirst]} {name, [ucfirst]}
strtoupper Transform the string to upper case {attribute_code, [strtoupper]} {name, [strtoupper]}
strtolower Transform the string to lower case {attribute_code, [strtolower]} {name, [strtolower]}
convert Change price currency {attribute_code, [convert from to ]} {price, [convert USD AUD]} or {special_price, [convert AUD CHF]}
number_format Format a number with grouped thousands {attribute_code, [number_format decimals]} {price, [number_format 2]} or Price comma format: {price, [number_format 2 , ]}
urlToUnsecure Convert all Urls to HTTP format {attribute_code, [urlToUnsecure]} {image, [urlToUnsecure]}
urlToSecure Convert all URLs to https format {attribute_code, [urlToSecure]} {image, [urlToSecure]}
only_parent Only add a variable product info {attribute_code, [only_parent]}
{description, [only_parent]}
parent
Variable product info if variable value is not empty else variation 
info
{attribute_code, [parent]}
{description, [parent]}
parent_if_empty
Add variable product info if the variation info is empty.
Example: Product Description
{attribute_code, [parent_if_empty]}
{description, [parent_if_empty]}




strip_shortcodes
Delete shortcodes from the string {attribute_code, [strip_shortcodes]} {description, [strip_shortcodes]}

Additional Patterns:

For PHP calculation and Ternary Operator you have to set attributes as PHP variable. For Example:  You want to multiply the price attribute value with 20. Then you have to set the price attribute as $price instead of {price}. {(return $price*20; )}. Don’t forget to add semicolon ; after the calculation.

Calculations:

  • {(return $price * 1.15;)}
  • {(return $qty + 1;)}
  • {(return $group_price2 / 10 * 4 – 2.5;)}
  • {(return str_replace(“0”, “*”, $sku);)}
  • {(return substr($sku, 3);)}
  • {(return str_replace(“a”, “b”, substr($sku, 0, 5));)}
  • {(return date(‘d.m.Y H:i:s’);)}
  • {(return date(‘d.m.Y H:i:s’, strtotime(‘+25 days’));)}
  • {(return date(“d/m/Y”, strtotime($special_from_date));)}

PHP Ternary Operator:

  • {(return ($price > 1000) ? ‘free shipping’ : ’15’;)}
  • {(return ($manage_stock == 1) ? $qty : 999;)}
  • {(return (strlen($manufacturer) > 1) ? $manufacturer : ‘NoBrand’;)}
  • {(return ($color!==’orange’) ? $color : ”;)}

WPML Price Conversion:

WPML Price conversion function needs the currency code in ISO 3 digit format. Use wpml_price as output formatter for the price tag.

Example: <price>{price,[wpml_price]} BDT</price>

10 thoughts
    1. Hi! Please, contact our technical support team from here or create a support ticket explaining your query. Our technical support team will reach you soon via email.

      1. Ah ok! Thanks for reply. But Ansary, a tip, want to sell a lot to the Brazilian market? Add the listing template, or the custom post type option with custom fields, there are no integrations with real estate portals to WordPress, and all portals use feed. This here is the feed format of one of the largest portals in Brazil https://developers-grupozap-com.translate.goog/feeds/vrsync/elements/listing/?_x_tr_sl=pt&_x_tr_tl=en&_x_tr_hl=pt-BR&_x_tr_pto=wapp#title

        1. I’m not sure if your store is based on WooCommerce. If you are using WooCommerce in your WordPress setup to create your store then you can create the above template using Cusotm template 2. To know more about it, please, reach us from here – webappick.com/contact

  1. Hi.

    Is there a way to run a custom function during generation?

    I have a function that takes the description and removes from it all the html elements that wouldn’t look good in the price comparison site my client shows his products in. I need it to work like clean_description($id)

    (It is important that the value that gets pushed to the function is the ID and not the description itself.)

    Is there a way to do it?

    1. Hi,

      We have built-in commands to remove HTML from the description, and here you can find them.
      Please, feel free to reach out to our support team for further queries.

      Thank you,

  2. Hi folks,

    Is it possible to do conditional attributes? I have certain products in my catalogue that I need to show additional attributes for, based on their category. E.g product is in Category A, add attribute X in addition to the defaults. Product is in Category B, and attributes Y and Z in addition to the defaults.

    Thanks,
    Brendan

    1. Hi Brendan,

      Yes, it’s possible to add additional attributes to the feed based on the product category and it can be done using our plugin Dynamic Attribute which is available in the pro version.
      To get step by step solution, please, reach out to our technical support team explaining what attributes you would be adding based on which categories.
      Please, create the ticket from here – webappick.com/contact

      Thank you,

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.