add_action( 'woocommerce_after_shop_loop_item', 'new_template_loop_product_meta', 20 );
function new_template_loop_product_meta() {
global $product;
$attr_list = [
'Brand' => 'pa_brand',
'Country' => 'pa_country',
'Material' => 'pa_material',
'Type' => 'pa_product_type',
'Color' => 'pa_color',
'Size' => 'pa_size',
'Model' => 'pa_model',
'Collection' => 'pa_collection',
'Mechanism' => 'pa_mechanism',
'Калибр' => 'pa_kalibr',
'Залпов' => 'pa_zalpov',
'Секунд' => 'pa_sekund',
];
if ( ! is_object( $product ) ) {
$product = wc_get_product( get_the_id() );
}
echo '<div class="pa">';
foreach ( $attr_list as $attr_title => $attr_name ) {
show_attribute( $product, $attr_title, $attr_name );
}
echo '</div>';
}
/**
* Show attribute.
*
* @param WC_Product $product Product.
* @param string $attr_title Attribute title.
* @param string $attr_name Attribute name.
*/
function show_attribute( $product, $attr_title, $attr_name ) {
if ( 'sku' === $attr_name ) {
$attr = (string) $product->get_sku();
} else {
$attr = $product->get_attribute( $attr_name );
}
if ( '' === $attr ) {
return;
}
echo '<span>' . esc_html( $attr_title ) . ': </span><span class="pa-right">' . esc_html( $attr ) . '</span><p>';
}