Script Php: differenze tra le versioni
Da Webmobili Wiki.
| Riga 26: | Riga 26: | ||
$fornitori = wp_get_post_terms($product->get_id(), 'pa_fornitore'); | $fornitori = wp_get_post_terms($product->get_id(), 'pa_fornitore'); | ||
$codici_fornitore = wp_get_post_terms($product->get_id(), 'pa_codice_fornitore'); | $codici_fornitore = wp_get_post_terms($product->get_id(), 'pa_codice_fornitore'); | ||
</syntaxhighlight> | |||
'''Recuperare tutti i termini (categorie + tag + attributi)''' | |||
<syntaxhighlight lang="php"> | |||
$taxonomies = get_object_taxonomies('product'); | |||
foreach ($taxonomies as $taxonomy) { | |||
$terms = wp_get_post_terms($product->get_id(), $taxonomy); | |||
if (!empty($terms)) { | |||
echo "<strong>{$taxonomy}:</strong> "; | |||
echo implode(', ', wp_list_pluck($terms, 'name')); | |||
echo "<br>"; | |||
} | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Versione delle 14:05, 5 ago 2025
Woocommerce
Qualsiasi tassonomia associata ai prodotti in WooCommerce.
Tassonomie standard WooCommerce
- Categorie prodotti
$categories = wp_get_post_terms($product->get_id(), 'product_cat');
- Tagprodotti
$tags = wp_get_post_terms($product->get_id(), 'product_tag');
Attributi globali WooCommerce
Gli attributi globali vengono registrati come tassonomie con prefisso pa_. Ad esempio:
- Attributo brand → tassonomia pa_brand
- Attributo fornitore → tassonomia pa_fornitore
- Attributo codice_fornitore → tassonomia pa_codice_fornitore
Quindi puoi recuperarli così:
$brands = wp_get_post_terms($product->get_id(), 'pa_brand');
$fornitori = wp_get_post_terms($product->get_id(), 'pa_fornitore');
$codici_fornitore = wp_get_post_terms($product->get_id(), 'pa_codice_fornitore');
Recuperare tutti i termini (categorie + tag + attributi)
$taxonomies = get_object_taxonomies('product');
foreach ($taxonomies as $taxonomy) {
$terms = wp_get_post_terms($product->get_id(), $taxonomy);
if (!empty($terms)) {
echo "<strong>{$taxonomy}:</strong> ";
echo implode(', ', wp_list_pluck($terms, 'name'));
echo "<br>";
}
}