Rankmath’s product schema cant take variable product ID as SKU

#42934
  • Resolved Quang Minh
    Rank Math free

    Hi,
    I have a question about Rankmath’s product schema:
    + When i turn on Rankmath’s product schema, the SKU field is empty & Google cant detech the product SKU.
    + When i turn off Rankmath’s product schema, Google takes the product variable ID as SKU

    Almost all of my woocommerce products are variable products, so I prefer to use varible products’ ID as SKU. How can i do it with Rankmath? Thank you.
    Pls take a look at below images:
    null
    null
    null

Viewing 6 replies - 1 through 6 (of 6 total)
  • Todd
    Rank Math free

    Hi QUang,

    Thanks for getting in touch with us.

    For the GTIN, ISBN, MPN issue, you can fix it by adding that to your products using the custom product attribute feature in WooCommere or you can use this plugin: https://wordpress.org/plugins/product-gtin-ean-uc-isbn-for-woocommerce/

    For the priceValidUntil warning, you have to either ignore that or add a sale price with validity to get rid of it: https://i.rankmath.com/cMqAAH

    Hope that helps and please do not hesitate to let me know if you need our assistance with anything else.

    Quang Minh
    Rank Math free

    Thanks for your reply.
    But i want to assign the variable product ID as SKU (as used in default woocommerce schema). Is it possible?
    Thank you!

    Michael Davis
    Rank Math pro

    Hello,

    Thank you for contacting Rank Math today.

    I have alerted our dev team about this and we will be investigating this further and get back to you.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    Please add following code in your theme’s functions.php file to use Variation ID in Product SKU Field:

    
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    	global $product;
    	if ( $product->is_type( 'variable' ) ) {
    		$variations = $product->get_available_variations();
    		foreach ( $variations as $key => $variation ) {
    			$entity['offers'][ $key ]['sku'] = ! empty( $entity['offers'][ $key ]['sku'] ) ? $entity['offers'][ $key ]['sku'] : $variation['variation_id'];
    		}
    	}
    
    	return $entity;
    });
    
    

    I hope that helps. If you need any other assistance, please feel free to let us know.

    Thank you.

    Quang Minh
    Rank Math free

    Hi,
    Thanks your guide but it doesnt work. It runs through all variations of a variable but the sku field is still empty! 🙁

    Hello,

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WP logins and the variable Product link in the designated Sensitive Data section.
    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,

    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 6 replies - 1 through 6 (of 6 total)

The ticket ‘Rankmath’s product schema cant take variable product ID as SKU’ is closed to new replies.