admin管理员组文章数量:1287831
I am using the following code for displaying a custom attribute on the Woocommerce shop page. But for some reason, the year is displayed above the product image instead of after the product title (In between the product title and the price).
add_action('woocommerce_after_shop_loop_item_title', 'YearOfMake', 10);
function YearOfMake()
{
global $product;
$abv = $product->get_attribute('year-made');
if (empty($abv))
return;
echo __($abv, 'woocommerce');
}
Link: /
I am using the following code for displaying a custom attribute on the Woocommerce shop page. But for some reason, the year is displayed above the product image instead of after the product title (In between the product title and the price).
add_action('woocommerce_after_shop_loop_item_title', 'YearOfMake', 10);
function YearOfMake()
{
global $product;
$abv = $product->get_attribute('year-made');
if (empty($abv))
return;
echo __($abv, 'woocommerce');
}
Link: https://groovygarbs/cars/
Share Improve this question edited Jan 29, 2019 at 11:18 pikaaaaaaaaa asked Jan 28, 2019 at 23:43 pikaaaaaaaaapikaaaaaaaaa 11 silver badge3 bronze badges2 Answers
Reset to default 1add_filter( 'the_title', 'YearOfMake', 10, 2 );
function YearOfMake( $title, $post_id )
{
if ( get_post_type( $post_id ) != 'product' && ! is_archive() )
return $title;
if ( ! ( is_shop() || is_product_category() || is_product_tag() ) )
return $title;
/*
global $product;
$attribute = 'year-made';
$abv = $product->get_attribute($attribute);
if(!empty($abv))
{
$title .= '<br /><p>' . $abv . '</p>';
}
*/
$terms = wp_get_post_terms( $post_id, 'product_tag' );
$term = reset( $terms );
if ( !empty( $term->name ))
{
$title .= '<br /><p>' . strtoupper( $term->name ) . '</p>';
}
return $title;
}
add_action('woocommerce_after_shop_loop_item_title', 'YearOfMake', 15);
function YearOfMake()
{
global $product;
$attribute = 'year-made';
$abv = $product->get_attribute($attribute);
if(!empty($abv))
{
echo '<p>' . $abv . '</p>';
}
}
本文标签: phpDisplay attribute on shop page after the title
版权声明:本文标题:php - Display attribute on shop page after the title 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741327289a2372562.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论