在Woocommerce产品页面上显示更多产品元信息


Showing more Product Meta info on Woocommerce product page

我目前正在使用40k +会员产品开发woocommerce网上商店。在添加到购物车按钮下方,woocommerce会自动显示SKU,类别和标签。但是我想添加产品元中提供的更多信息,例如尺寸、颜色和品牌。

我已经搞砸了元.php但到目前为止没有运气。我尝试添加几个变量,例如:

现存:

 $cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) );

我补充说:

 $col_count = sizeof( get_the_terms( $post->ID, 'product_col' ) );

在div 类"product_meta"中,它声明如下:

<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '</span>' ); ?>

添加:

<?php echo $product->get_colors( ', ', '<span class="posted_in">' . _n( 'Color:', 'Colors:', $col_count, 'woocommerce' ) . ' ', '</span>' ); ?>

但是没有成功。 不是一个有经验的程序员,所以如果我做了一些完全愚蠢的事情,请原谅我。

带着亲切的问候,

鲁迪

例如,

您可以在WooCommerce中使用产品属性:

  1. 在管理仪表板上打开"产品"部分
  2. 打开"属性"子部分
  3. 创建必需的属性(例如颜色)并保存此属性
  4. 转到产品编辑页面
  5. 打开"属性"选项卡并设置属性值
  6. 保存产品

之后,您需要覆盖WooCommerce模板文件(.../wp-content/plugins/woocommerce/templates/single-product/meta.php)

在元.php中复制此代码:

$attributes = $product->get_attributes();
foreach ( $attributes as $attribute ) {
    print_r( wc_attribute_label( $attribute[ 'name' ] ) . ': ' );
    print_r( array_shift( wc_get_product_terms( $product->id, $attribute[ 'name' ] ) );
}

有关向WC商店页面添加信息的更多信息,请点击此处:

https://www.skyverge.com/blog/add-information-to-woocommerce-shop-page/