Website Building » WooCommerce » What Is Schema in WooCommerce?

What Is Schema in WooCommerce?

Last updated on January 23, 2023 @ 11:09 am

Schema is an important part of WooCommerce. It is basically a code that helps search engines understand the content on your website.

This is important because it allows them to show your site in search results.

There are many different types of schema, but the most common one used in WooCommerce is called “Product”. This type of schema is used to help search engines understand the products that you sell on your website.

Product schema includes information like the name of the product, the price, the description, and more.

In order to add product schema to your WooCommerce site, you need to add a few lines of code to your theme’s functions.php file. You can find this file in your WordPress installation folder > wp-content > themes > your-theme-name. Once you have located the file, you will need to add the following code:

PRO TIP: Schema in WooCommerce can refer to a number of things:

1. The structure of your data
2. A way of organizing your data
3. A set of rules or guidelines for how your data should be formatted

If you’re not careful, schema can cause problems with your data. For example, if you change the structure of your data, you may need to update your schema accordingly. Additionally, if you don’t follow the rules of schema, your data may not be formatted correctly and could cause issues.

function WooCommerce_product_schema() 
{$schema = array(
        '@context'      => 'http://schema.org/',
        '@type'         => 'Product',
        'name'          => get_the_title(),
        'image'         => wp_get_attachment_url( get_post_thumbnail_id()
),
        'description'   => get_the_excerpt(),
        'sku'           => get_post_meta( get_the_ID(), '_sku', true ),   ); 

    if ( $price = get_post_meta( get_the_ID(), '__wcspc', true ) ) {

        $schema['offers'] = array(
            '@type'          => 'Offer',             
            'priceCurrency'  => get_woocommerce_currency(),             
            'price'          => $price, );} 
    echo '<script type="application/ld+json">';     
    echo wp_json_encode( $schema );     
    echo '</script>';} 
add_action( 'wp', 'woocommerce_product_schema' );

This code will add product schema to every single product page on your website. If you only want to add it to certain pages, you can use a conditional statement like this:

if ( is_singular( ‘product’ ) ) 
{ WooCommerce_product _ schema();}

Schema is a great way to help search engines understand your content better. By adding product schema to your WooCommerce site, you can make sure that your products show up in search results. This can help you increase traffic and sales.

Morgan Bash

Morgan Bash

Technology enthusiast and Co-Founder of Women Coders SF.