Showing more Product Meta info on Woocommerce product page

。_饼干妹妹 提交于 2019-12-13 00:54:42

问题


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.

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

existing:

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

i added:

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

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

added:

<?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.

With kind regards,

Rudy


回答1:


For example you can use product attributes in WooCommerce:

  1. Open 'Products' section on Admin Dashboard
  2. Open 'Attributes' subsection
  3. Create required attributes (e.g. Color) and save this
  4. Go to product editing page
  5. Open 'Attributes' tab and set attribute(s) value(s)
  6. Save product

After that you need override WooCommerce template file (.../wp-content/plugins/woocommerce/templates/single-product/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' ] ) );

}

More about adding information to WC Shop Pages here:

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



来源:https://stackoverflow.com/questions/35089718/showing-more-product-meta-info-on-woocommerce-product-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!