MPN and GTIN snippet

#497101
  • Resolved Cosmin Pirvan
    Rank Math free

    Dear team,

    Please provide a snippet for adding MPN and GTIN
    In one of your older post i found a snippet but it does not work. The custom attributes that i created in Woocommerce are called MPN and GTIN.

    <?php
    /**
    * Filter to add MPN Name for Products.
    *
    * @param array $entity Snippet Data
    * @return array
    */
    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    $entity[‘MPN’][‘@type’] = ‘MPN’;
    $entity[‘MPN’][‘name’] = ‘Rank Math’;
    return $entity;
    });

Viewing 1 replies (of 1 total)
  • Hello,

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

    Please refer to this filter if you wish to apply a woocommerce attribute to a schema property:

    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
    	global $product;
    	$attr_1 = $product->get_attribute( 'YOUR_ATTRIBUTE_1' );
    	$attr_2 = $product->get_attribute( 'YOUR_ATTRIBUTE_2' );
    	$attr_3 = $product->get_attribute( 'YOUR_ATTRIBUTE_3' );
    
    	$entity['gtin'] = $attr_1;
    	$entity['mpn'] = $attr_2;
    	$entity['name'] = $attr_3;
    	return $entity;
    });

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

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

The ticket ‘MPN and GTIN snippet’ is closed to new replies.