您不需要在外部为此编写代码。请参考以下截图:

如上图所示,从仪表板添加产品属性。

在前端,产品属性将显示在“附加信息”部分下。
希望您的问题得到解决,如果没有,请在下面发表评论。
Answer for updated question:
由于要在产品列表页面上显示产品属性,只需在函数中添加以下行即可。php
add_action(\'woocommerce_after_shop_loop_item_title\', \'show_attr\');
function show_attr()
{
global $product;
$product->list_attributes();
}
产品列表页面如下所示:
