Google Merchant Centre with Woocommerce Variations

#406021
Viewing 15 replies - 1 through 15 (of 21 total)
  • Hey,

    So further to this, I’ve found this post;

    So I have tried turning off the schema from RankMath and using the Product Feed Pro option seen here;
    https://adtribes.io/woocommerce-structured-data-bug/?utm_source=www.grainandframe.com&utm_medium=manage-settings&utm_content=structured%20data%20bug

    And I manage to get the following result, which is great as the price for the variant product is correct but means I need to turn off all of the RankMath Schema which isn’t something we can do;

    Price Google Rich Result

    https://search.google.com/test/rich-results/result?id=isCxBlW2ZCSp5AeLD535bQ

    I’ve also tried the following code, with the schema enabled;

    add_filter( 'rank_math/woocommerce/og_price', 'my_custom_og_tags' );
    function my_custom_og_tags(){
      global $product;
      if($product->is_type('variable')){
         return false;
    }
      return true;
    
    }

    However, this doesn’t fix the price issue for the variant and I think this is because the Product Feed Elite can only resolve Woocommerce’s original schema not the altered one by RankMath.

    Anything you can do to help?

    Thanks,
    Sam

    Nigel
    Rank Math business

    Hello,

    Thank you for contacting us for help with your Google Merchant Center (GMC) variable product schema issues.

    GMC requires that each variation have a price in the product schema. The default Rank Math product schema does not add separate prices for variable products. However you can add the code snippet below to add offers schema for each product variation:

    
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        if ( ! is_product() ) {
            return $entity;
        }
        
        $product = wc_get_product( get_the_ID() );
        if ( ! $product->is_type( 'variable' ) ) {
            return $entity;
        }
        
        $variations = $product->get_available_variations();
    
        if ( ! empty( $variations ) ) {
            $offers = [];
            foreach ( $variations as $variation ) {
                $price_valid_until = get_post_meta( $variation['variation_id'], '_sale_price_dates_to', true );
    
                $offers[] = [
    				'@type'           => 'Offer',
    				'description'     => strip_tags( $variation['variation_description'] ),
    				'price'           => $variation['display_price'],
    				'priceCurrency'   => get_woocommerce_currency(),
    				'availability'    => $variation['is_in_stock'] ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock',
    				'priceValidUntil' => $price_valid_until ? date_i18n( 'Y-m-d', $price_valid_until ) : '2025-12-31',
    				'url'             => $product->get_permalink(),
    			];
            }
        }
        
        $entity['offers'] = $offers;
        
        return $entity;
    } );
    

    Once you have implemented the code snippet above, you may need to request a recrawl from GMC.

    Hope that helps. Please let us know if you have questions.

    Good Morning,

    Is there any update on this, as I’d like to get it resolved so we can get these products live on shopping?

    Thanks,
    Sam

    Hi Nigel,

    Thanks for taking the time to look into this for us and create the code above.

    However, there seems to be quite a difference from when we switch off the Rank Math Schema completely and use the Product Feed Elite setting compared to the code above.

    This is the that result;

    and this is the result from using the code above;

    The new code seems to load every variant price all with the same URL, whereas the previous one has one specific price and a unique URL for that variant.

    Is it possible to amend the RankMath code to do the same?

    Thank you,
    Sam

    The URLs for the rich results tests don’t seem to be included,

    Here they are again;

    Fully disabled Rank Math schema with Product Feed Elite;
    https://search.google.com/test/rich-results/result/r%2Fproduct?id=isCxBlW2ZCSp5AeLD535bQ

    Rank Math schema enabled with modified code above;
    https://search.google.com/test/rich-results/result/r%2Fproduct?id=a2jDNciuWTA_pCagpZtIvg

    Thanks,
    Sam

    Hello,

    In the filter code my colleague provided, the URL per variation is inserted with the same URL as the current product so it would generate the same URL for every offer property in the schema.

    If you wish to add the URL as the actual variation URL, try this code instead:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        if ( ! is_product() ) {
            return $entity;
        }
        
        $product = wc_get_product( get_the_ID() );
        if ( ! $product->is_type( 'variable' ) ) {
            return $entity;
        }
        
        $variations = $product->get_available_variations();
    
        if ( ! empty( $variations ) ) {
            $offers = [];
            foreach ( $variations as $variation ) {
                $price_valid_until = get_post_meta( $variation['variation_id'], '_sale_price_dates_to', true );
    
                $current_url = parse_url($product->get_permalink());
                $parameters = array();
                foreach ($variation['attributes'] as $attribute_key => $attribute){
                    $parameters[$attribute_key] = $attribute;
                }
    
                $offers[] = [
    				'@type'           => 'Offer',
    				'description'     => strip_tags( $variation['variation_description'] ),
    				'price'           => $variation['display_price'],
    				'priceCurrency'   => get_woocommerce_currency(),
    				'availability'    => $variation['is_in_stock'] ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock',
    				'priceValidUntil' => $price_valid_until ? date_i18n( 'Y-m-d', $price_valid_until ) : '2025-12-31',
    				'url'             => $product->get_permalink() . '?' . http_build_query($parameters, '', '&'),
    			];
            }
        }
        
        $entity['offers'] = $offers;
        
        return $entity;
    } );

    Let us know how that goes. Looking forward to helping you on this one.

    Hi Jeremy,

    Thanks for the support.

    It improved it, the prices are now on there with unique URLs.
    However, not every variant is being pulled through.

    For example;
    The opening price point for the table is a 4-seater starting at 399
    https://www.grainandframe.com/dining-tables/farmhouse-dining-table/

    When I look at the rich results, there is no 399 price point and no 4-seater attribute as a product within the list;
    https://search.google.com/test/rich-results/result?id=LWUSLmCv8EIcubHd1kW84g

    Thanks,
    Sam

    Hello,

    In this case, we might need to check this one over your admin dashboard. Please edit the first post on this ticket and include your WordPress login in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    The link you have shared in the sensitive data section is working, however, we’re unable to access your WordPress dashboard. I’ve tried the URL /wp-admin, but it is always getting redirected to the /my-account page.

    Could you please check?

    Looking forward to helping you.

    Thank you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hi,

    I’ve shared the link for the WP backend in sensitive data.

    Thanks,
    Sam

    Hello,

    After running the temporary login URL you shared, I went ahead and access the WP-admin URL, but I was again asked for a username and password as you can see in my screenshot in the Sensitive Data section.

    Can you please share the username and password instead?

    Looking forward to helping you on this one.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    Allow me to further check this issue with our development team. We should get back to you shortly with an update.

    We appreciate your time and patience on this one.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 15 replies - 1 through 15 (of 21 total)

The ticket ‘Google Merchant Centre with Woocommerce Variations’ is closed to new replies.