Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.