add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) { // Exit if 'offers' isn't set at all if ( ! isset( $entity['offers'] ) ) { return $entity; } // --- Define the policies once --- $return_policy = [ '@type' => 'MerchantReturnPolicy', 'applicableCountry' => 'IR', 'returnPolicyCategory' => 'https://schema.org/MerchantReturnFiniteReturnWindow', 'merchantReturnDays' => 7, 'returnMethod' => 'https://schema.org/ReturnByMail', 'returnFees' => 'https://schema.org/FreeReturn', ]; $shipping_details = [ '@type' => 'OfferShippingDetails', 'shippingRate' => [ '@type' => 'MonetaryAmount', 'value' => 0, 'currency' => 'IRR', ], 'shippingDestination' => [ '@type' => 'DefinedRegion', 'addressCountry' => 'IR', ], ]; // --- End Definitions --- // Check if 'offers' is an array of offers (e.g., variable product) if ( isset( $entity['offers'][0] ) ) { // Loop through each offer (for variable products) foreach ( $entity['offers'] as $key => $offer ) { $entity['offers'][ $key ]['hasMerchantReturnPolicy'] = $return_policy; $entity['offers'][ $key ]['shippingDetails'] = $shipping_details; } } else { // It's a single offer object (for simple products) $entity['offers']['hasMerchantReturnPolicy'] = $return_policy; $entity['offers']['shippingDetails'] = $shipping_details; } return $entity; }); https://copify.ir/post-sitemap.xml 2025-11-07T09:56:11+00:00 https://copify.ir/page-sitemap.xml 2025-11-07T09:15:38+00:00 https://copify.ir/product-sitemap.xml 2025-11-07T10:43:59+00:00 https://copify.ir/portfolio-sitemap.xml 2025-01-23T07:17:38+00:00