-
Hi team,
Thanks as always.
I would love to apply Product scheme to these custom posts called “inventory” (See sensitive data section for URL)As “inventory” posts already has price, availability values and such, so I’d love them to be automatically applied to Scheme fields, without setting them manually in RankMath settings.
Do I need to tweak php code to do this?
To manage the custom fields we use SCF not ACF, and a custom field “inventory_situation” contains availability(“soldout” is a value when unavailable), “inventory_price” contains its price information in JPY.Here’s a mock code, that off course didn’t work 😛
add_action('save_post_inventory', function($post_id) {
// retrieve custom fields value
$situation = get_post_meta($post_id, 'inventory_situation', true);
$price = get_post_meta($post_id, 'inventory_price', true);// Rank Mathのスキーマデータを取得
$schema = get_post_meta($post_id, 'rank_math_schema_Product', true);if ($schema) {
// スキーマデータを更新
$schema['price'] = $price;
$schema['availability'] = ($situation == 'soldout') ? 'OutOfStock' : 'InStock';// 更新したスキーマデータを保存
update_post_meta($post_id, 'rank_math_schema_Product', $schema);
}
});
Thanks for your help, in advance
Mayumi
You must be logged in to reply to this ticket.