Skip to content

Instantly share code, notes, and snippets.

@DxDiagDx
Last active October 5, 2021 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DxDiagDx/337865abce372ea8aa3a2cb5e747be26 to your computer and use it in GitHub Desktop.
Save DxDiagDx/337865abce372ea8aa3a2cb5e747be26 to your computer and use it in GitHub Desktop.
Woo: вывести значения атрибута в коротком описании карточки товара
/*
* Вывод атрибутов в коротком описании
*/
add_action( 'woocommerce_single_product_summary', 'show_attr_singe_product', 21 );
function show_attr_singe_product() {
global $product;
// Получаем элементы таксономии атрибута color
$attribute_names = get_the_terms($product->get_id(), 'pa_color');
$attribute_name = "pa_color";
if ($attribute_names) {
// Вывод имени атрибута
echo wc_attribute_label($attribute_name);
// Выборка значения заданного атрибута
echo '<ul>';
foreach ($attribute_names as $attribute_name):
// Вывод значений атрибута
echo '<li>' . $attribute_name->name . '</li>';
endforeach;
echo '</ul>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment