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

时间:2016-01-29 16:44:31

标签: php wordpress woocommerce field meta

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

我已经弄乱了Meta.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>' ); ?>
然而,没有成功。不是一个经验丰富的编码员,如果我做了一些完全愚蠢的话,请原谅我。

亲切的问候,

鲁迪

1 个答案:

答案 0 :(得分:1)

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

  1. 在管理仪表板上打开“产品”部分
  2. 打开“属性”小节
  3. 创建所需的属性(例如Color)并保存此
  4. 转到产品编辑页面
  5. 打开“属性”标签并设置属性值
  6. 保存产品
  7. 之后你需要覆盖WooCommerce模板文件(... / wp-content / plugins / woocommerce / templates / single-product / meta.php)

    将此代码复制到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 Shop Pages添加信息的信息:

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