Hello,
Thank you for contacting Rank Math support.
You can use the following filter to add the itemList Schema with details of each product to the category pages:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
if(is_product_category()) {
$products = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => get_queried_object_id(),
)
),
));
$data['itemList']['itemListElement'] = [];
foreach($products as $key => $product) {
$url = get_the_permalink($product);
$schema[] = [ "@type"=> "ListItem",
"position"=> $key,
"item" => [
"@type" => "Product",
"name" => get_the_title($product),
"url"=> $url,
"image" => get_the_post_thumbnail_url($product, 'full'),
"offers" => [
"@type" => "offer",
"priceCurrency" => "PKR",
"price" => wc_get_product($product)->get_price()
],
]
];
$data['itemList']['@type'] = 'itemList';
$data['itemList']['itemListElement'] = $schema;
}
}
return $data;
}, 99, 2);
Here is how to add a filter to your site: https://rankmath.com/kb/wordpress-hooks-actions-filters/
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.