首页 文章

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

提问于
浏览
1

我目前正在使用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 回答

  • 1

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

    • 在管理仪表板上打开'Products'部分

    • 打开'Attributes'小节

    • 创建必需的属性(例如颜色)并保存

    • 转到产品编辑页面

    • 打开'Attributes'选项卡并设置属性(s)值

    • 保存产品

    之后你需要覆盖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/

相关问题