Support Log in

42. Integration with WooCommerce SEO

Developer Guide
Prefer video? Watch the Rank Forge tutorials 9 short guides covering every feature Watch

Rank 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, Rank Forge auto-generates Product schema:

php
// Rank Forge auto-detects 'product' post type and generates:
// @type: Product, with name, description, image, offers (price, availability), brand

Custom Product Meta Templates

php
update_option( 'rankforge_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( 'rankforge_sitemap_settings', [] );
$enabled  = $settings['enabled_types'] ?? [ 'post', 'page' ];
if ( ! in_array( 'product', $enabled, true ) ) {
    $enabled[] = 'product';
    $settings['enabled_types'] = $enabled;
    update_option( 'rankforge_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 );

Forge AI Assistant Online

Hi! I'm the Rank Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs