在Woocommerce产品页面上显示更多产品元信息 [英] Showing more Product Meta info on Woocommerce product page

查看:190
本文介绍了在Woocommerce产品页面上显示更多产品元信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently working on a woocommerce webshop using 40k+ affiliate products. Below the add to cart button woocommerce automaticly shows SKU, Category and Tags. however i would like to add more info provided in the Product meta such as size, color and brand.

我已经弄乱了Meta.php,但是到目前为止还没有运气. 我尝试添加几个变量,例如:

I've messed around with the Meta.php however no luck so far. I've tried adding several variables eg:

现有:

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

我添加了:

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

在div类"product_meta"中声明以下内容:

in the div class "product_meta" it states the following:

<?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>' ); ?>

但是没有成功.不是经验丰富的编码人员,所以请问我做些完全愚蠢的事情.

however no succes. not an experienced coder so excuse me if i did somethin completely idiotic.

以诚挚的问候,

鲁迪

推荐答案

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

For example you can use product attributes in WooCommerce:

  1. 在管理控制台上打开产品"部分
  2. 打开属性"小节
  3. 创建必需的属性(例如颜色)并保存
  4. 转到产品编辑页面
  5. 打开属性"标签并设置属性值
  6. 保存产品

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

After that you need override WooCommerce template file (.../wp-content/plugins/woocommerce/templates/single-product/meta.php)

将此代码复制到meta.php中:

Copy this code in meta.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商店页面添加信息的更多信息:

More about adding information to WC Shop Pages here:

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

这篇关于在Woocommerce产品页面上显示更多产品元信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆