Add Merchant fields to WooCommerce offers

I’ve been asked several times how to extend the WooCommerce: Offers” field type to include the Offer schema with additional information like hasMerchantReturnPolicy and shippingDetails. Here’s how to do it.

First, the bad news: SNIP’s built-in schema builder is currently unable to include these fields. The “WooCommerce: Offers” field type I introduced taps into the WooCommerce data to “manually” construct the Offers schema based on its information. In addition, it is not advisable to integrate fields such as hasMerchantReturnPolicy and shippingDetails directly into the product schema, which is the precursor to the offer schema. This is because, as explained on Google’s documentation page, these fields are not essential for a product schema.

I understand why these fields may be essential in certain situations. That’s why I’m offering a simple plugin, which you can download here, that includes these fields. Just open the PHP file and edit the lines to suit your needs.

What you should edit:

The according PHP function may then look like this:

function offers_with_merchant( $val, \wpbuddy\rich_snippets\Rich_Snippet $rich_snippet, array $meta_info ) {
	$offers = \wpbuddy\rich_snippets\pro\WooCommerce_Model::offers( $val, $rich_snippet, $meta_info );

	$offers->hasMerchantReturnPolicy                       = new \stdClass();
	$offers->hasMerchantReturnPolicy->type                 = 'MerchantReturnPolicy';
	$offers->hasMerchantReturnPolicy->merchantReturnDays   = 30;
	$offers->hasMerchantReturnPolicy->applicableCountry    = 'US';
	$offers->hasMerchantReturnPolicy->returnPolicyCategory = '';
	$offers->hasMerchantReturnPolicy->returnMethod         = '';
	$offers->hasMerchantReturnPolicy->returnFees           = '';

	$offers->shippingDetails                                      = new \stdClass();
	$offers->shippingDetails->type                                = 'OfferShippingDetails';
	$offers->shippingDetails->shippingRate                        = new \stdClass();
	$offers->shippingDetails->shippingRate->type                  = 'MonetaryAmount';
	$offers->shippingDetails->shippingRate->currency              = 'USD';
	$offers->shippingDetails->shippingRate->value                 = 0;
	$offers->shippingDetails->shippingDestination                 = new \stdClass();
	$offers->shippingDetails->shippingDestination->type           = 'DefinedRegion';
	$offers->shippingDetails->shippingDestination->addressCountry = 'US';

How to install

Once you’ve finished editing the file, upload it to the wp-content/plugins/ folder in your WordPress installation. Alternatively, you can compress the file into a ZIP format and upload it directly from your WordPress dashboard by going to Plugins > Add New > Upload Plugin (button).

How to use

  1. After you’ve installed and activated the plugin, navigate to the Global Snippets section.
  2. Then choose the Schema Template you wish to modify by adding new fields.
  3. Add a new “offers” property or edit the existing one.
  4. Select “WooCommerce: Offers with Merchant data” from the list of field types. That’s all there is to it!