Missing field “SKU and MPN”

#209107
  • Resolved Laptop Titan
    Rank Math free

    I read the article Missing field “priceValidUntil” at https://support.rankmath.com/ticket/missing-field-pricevaliduntil/ and did it successfully. Appreciate the help of Team Rankmath

    But I have one more problem which is missing SKU and MPN fields.

    The idea I came up with is to get the ID of the product and add it to the SKU and MPN fields. (Because there are so many products, I can’t do this manually)

    It looks like this (Might be wrong because I’m not good at coding)

    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
    $product->get_id();
    $entity['offers']['priceValidUntil'] = '2023-06-01';
    $entity['sku'] = $product;
    $entity['mpn'] = $product;
    return $entity;
    });

    I need a piece of code that is correct and error free. Thank you, Rankmath. I would love to use your Plugins.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ankit
    Rank Math business

    Hello,

    Thank you for contacting the support and sorry for any inconvenience that might have been caused due to that.

    You can use the below filter to add/modify the value of SKU and MPN.

    Modify the Your-SKU and Your-MPN value according to your needs and paste the filter code to your current theme’s fucntion.php file.

    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
    $entity['sku'] = 'Your-SKU'; //
    $entity['mpn'] = 'Your-MPN';
    return $entity;
    });

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

    Has been successful! The final code that I get is like this

    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
    	$id = get_the_ID();
    	$entity['offers']['priceValidUntil'] = '2023-06-01';
    	$entity['sku'] = $id;
    	$entity['mpn'] = $id;
    	return $entity;
    });

    Thank you for your support !

    Ankit
    Rank Math business

    Hello,

    Glad that helped.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

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

The ticket ‘Missing field “SKU and MPN”’ is closed to new replies.