Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/Extensions/WPGraphQLWooCommerce/Type/WPObject/SeoObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,45 @@ public static function init(): void {
public static function register(): void {
// Set SEO field types for product children.
$product_types = WP_GraphQL_WooCommerce::get_enabled_product_types();
/**
* @todo: remove this when we don't need to support WooGraphQL< 0.21.1
* @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767
*/
if ( defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) && version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.21.1', '>=' ) ) {
$product_types = array_merge(
$product_types,
[
'ProductUnion',
'ProductWithPricing',
'ProductWithDimensions',
'InventoriedProduct',
'DownloadableProduct',
'ProductWithAttributes',
'ProductWithVariations',
]
);
}

foreach ( $product_types as $graphql_type_name ) {
Utils::overload_graphql_field_type( $graphql_type_name, 'seo', 'RankMathProductObjectSeo' );
}

/**
* @todo: remove this when we don't need to support WooGraphQL< 0.21.1
* @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767
*/
if ( defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) && version_compare( WPGRAPHQL_WOOCOMMERCE_VERSION, '0.21.1', '<' ) ) {
self::register_product_variation_types();
}
}

/**
* Registers the SEO types for product variations.
*
* @todo: remove this when we don't need to support WooGraphQL< 0.21.1
* @see https://github.com/AxeWP/wp-graphql-rank-math/pull/115#issuecomment-2660900767
*/
private static function register_product_variation_types(): void {
// Register the Product Variation SEO type and apply it to the Product Variation and children.
$type_name_for_product_variation = 'RankMathProductVariationObjectSeo';

Expand Down
Loading