Skip to content

Instantly share code, notes, and snippets.

@hereswhatidid
Created September 11, 2018 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hereswhatidid/b4b490ce1c04df49a890d3d958110a71 to your computer and use it in GitHub Desktop.
Save hereswhatidid/b4b490ce1c04df49a890d3d958110a71 to your computer and use it in GitHub Desktop.
Customize the schema for WooCommerce products
<?php
/*
* This class will customize the WooCommerce product schema markup
*/
namespace HWID\Woo;
class CustomizeSchema {
static function init() {
add_filter( 'woocommerce_structured_data_product', [ 'HWID\Woo\CustomizeSchema', 'override_schema_markup' ], 10, 2 );
}
/**
* Remove pricing information from the schema for a product that's only available as a quote
*
* @param array $markup
* @param \WC_Product $product
*
* @return array
*/
static function override_schema_markup( $markup, $product ) {
$availability = get_post_meta( $product->get_id(), '_product_availability', true );
if ( $availability === 'quote' ) {
$markup['offers'] = [];
}
return $markup;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment