shipping_weight tag in schema markup

#535884
  • Resolved Lord Gliess
    Rank Math free

    Hi,
    I am a user of rank math seo free edition. I want to synchronize my products with google merchant center using the schema markups. Currently I have problems because I configure my shipping details with a weight rule, but the shipping_weight tag is missing.
    Is there a way to add this tag ? And to fill a custom value ? (I prefer not to use the shipping weight value in woocommerce because of the unit which is in g and not available for google, and I prefer not to modify all of my shipping configuration in woommerce). Maybe using the rank math pro version ? I have read your knowledge base but didn’t found the solution..
    Thank you in advance

    Xavier

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    You can use and customize this filter to add the shipping_weight tag to your schema:
    https://rankmath.com/kb/filters-hooks-api-developer/#extend-json-ld-data

    And here’s a sample filter you can use to change the unit value in case you wanted to use the data directly from your WooCommerce setup (kg):

    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
    	global $product;
    	if (is_product()) {
    		$entity["shipping_weight"] = $product->get_weight()." kg";
    		return $entity;
    	}
     return $entity;
    });

    Hope that helps.

    Thank you.

    Hi, thank you Reinelle for the tip ! Don’t worry, actually rank math is much more a solution than a problem 🙂
    I have tested your solution, and it seems to work fine, but only in case of normal products. In the case of variable products, the weight and shipping_weight fields are empty. My problem is that each variation has its own weight. Do you have any idee of how I can deal with that ?
    thank you very much
    Xavier

    Nigel
    Rank Math business

    Hello,

    I have modified the filter to work for variable products. Please replace the previous filter with the one below:

    
    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
    	global $product;	
    	
    	if (is_product()) {
    		if( $product->is_type( 'variable' ) ){
    			foreach ( $product->get_visible_children() as $variation_id ) {
    				$variation = wc_get_product( $variation_id ); // Get the product variation object
    				$weight    = $variation->get_weight(); // Get weight from variation
    				$entity["shipping_weight"] = $weight." kg";
    			}
    		}
    		$entity["shipping_weight"] = $product->get_weight()." kg";
    		return $entity;
    	}
    	return $entity;
    });
    

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

    Ok thanks a lot, it works fine. I just put the line “$entity[“shipping_weight”] = $product->get_weight().” kg”;” before “if( $product->is_type( ‘variable’ ) )” because the result was overwritten in case of variable products.
    Have a great day.

    Xavier

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘shipping_weight tag in schema markup’ is closed to new replies.