Created
September 11, 2018 13:47
-
-
Save hereswhatidid/b4b490ce1c04df49a890d3d958110a71 to your computer and use it in GitHub Desktop.
Customize the schema for WooCommerce products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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