// Yoast: po WP All Importu nastavi najglobljo product_cat kot primarno add_action('pmxi_saved_post', function ($post_id) { if (get_post_type($post_id) !== 'product') return; $terms = wp_get_post_terms($post_id, 'product_cat', ['fields' => 'all']); if (empty($terms) || is_wp_error($terms)) return; // izberi najglobljo kategorijo (največ prednikov) $deepest = null; $max_depth = -1; foreach ($terms as $t) { $depth = count(get_ancestors($t->term_id, 'product_cat')); if ($depth > $max_depth) { $max_depth = $depth; $deepest = $t; } } if (!$deepest) return; // YOAST primary update_post_meta($post_id, '_yoast_wpseo_primary_product_cat', $deepest->term_id); }, 20);