Last active
October 5, 2021 14:37
-
-
Save DxDiagDx/337865abce372ea8aa3a2cb5e747be26 to your computer and use it in GitHub Desktop.
Woo: вывести значения атрибута в коротком описании карточки товара
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Вывод атрибутов в коротком описании | |
*/ | |
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