SEO Forge automatically detects WooCommerce products and generates Product schema. This section covers advanced integration patterns.
Automatic Product Schema
When WooCommerce is active and a product post type is detected, SEO Forge auto-generates Product schema:
php
// SEO Forge auto-detects 'product' post type and generates:
// @type: Product, with name, description, image, offers (price, availability), brandCustom Product Meta Templates
php
update_option( 'seoforge_title_templates', [
'product' => [
'title' => 'Buy {{title}} {{separator}} {{siteName}}',
'description' => '{{excerpt}} | Free shipping on orders over $50.',
],
] );Including Products in the Sitemap
php
$settings = get_option( 'seoforge_sitemap_settings', [] );
$enabled = $settings['enabled_types'] ?? [ 'post', 'page' ];
if ( ! in_array( 'product', $enabled, true ) ) {
$enabled[] = 'product';
$settings['enabled_types'] = $enabled;
update_option( 'seoforge_sitemap_settings', $settings );
}Enhancing Product Schema with WooCommerce Data
php
add_action( 'wp_head', function () {
if ( ! is_singular( 'product' ) || ! function_exists( 'wc_get_product' ) ) {
return;
}
$product = wc_get_product( get_the_ID() );
if ( ! $product ) {
return;
}
$schema = [
'@context' => 'https://schema.org',
'@type' => 'Product',
'name' => $product->get_name(),
'sku' => $product->get_sku(),
'offers' => [
'@type' => 'Offer',
'price' => $product->get_price(),
'priceCurrency' => get_woocommerce_currency(),
'availability' => $product->is_in_stock()
? 'https://schema.org/InStock'
: 'https://schema.org/OutOfStock',
],
];
// Add aggregate rating if reviews exist
if ( $product->get_review_count() > 0 ) {
$schema['aggregateRating'] = [
'@type' => 'AggregateRating',
'ratingValue' => $product->get_average_rating(),
'reviewCount' => $product->get_review_count(),
];
}
echo '<script type="application/ld+json">'
. wp_json_encode( $schema, JSON_UNESCAPED_SLASHES )
. '</script>' . "n";
}, 7 );—