Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在woocommerce 3的购物车页面上显示变体的产品属性_Php_Wordpress_Woocommerce_Attributes_Cart - Fatal编程技术网

Php 在woocommerce 3的购物车页面上显示变体的产品属性

Php 在woocommerce 3的购物车页面上显示变体的产品属性,php,wordpress,woocommerce,attributes,cart,Php,Wordpress,Woocommerce,Attributes,Cart,如何在购物车页面上显示产品类别及其变体 这是关于一个变化的产品 属性包含在变体中 没有其他属性(未为变体设置) 要显示变体的产品属性,有两种方法: 请参见以下相关答案: 要显示产品类别,可以使用此挂钩功能: add_filter( 'woocommerce_cart_item_name', 'customizing_cart_item_data', 10, 3); function customizing_cart_item_data( $item_name, $cart_item, $car

如何在购物车页面上显示产品类别及其变体

  • 这是关于一个变化的产品
  • 属性包含在变体中
  • 没有其他属性(未为变体设置)

要显示变体的产品属性,有两种方法:

请参见以下相关答案:

要显示产品类别,可以使用此挂钩功能:

add_filter( 'woocommerce_cart_item_name', 'customizing_cart_item_data', 10, 3);
function customizing_cart_item_data( $item_name, $cart_item, $cart_item_key ) {
    $term_names = array();

    // Get product categories
    $terms = wp_get_post_terms( $cart_item['product_id'], 'product_cat' );

    if( count($terms) > 0 ){
        foreach( $terms as $term ) $term_names[] = $term->name;

        $item_name .= '<p class="item-category" style="margin:12px 0 0; font-size: .875em;">
            <strong class="label">' . _n( 'Category', 'Categories', count($terms), 'woocommerce' ) . ': </strong>
            <span class="values">' . implode( ', ', $term_names ) . '</span>
        </p>';
    }
    return $item_name;
}
add_filter('woocommerce_cart_item_name','customization_cart_item_data',10,3);
自定义购物车项目数据的函数($item\u name、$cart\u item、$cart\u item\u key){
$term_names=array();
//获取产品类别
$terms=wp_get_post_terms($cart_item['product_id'],'product_cat');
如果(计数($terms)>0){
foreach($terms as$term)$term\u name[]=$term->name;
$item_name.='

。\n('Category','Categories',count($terms),'woocommerce'): “.内爆(”,“,$term_名称)。”

'; } 返回$item_name; }
代码位于活动子主题(或主题)的function.php文件或任何插件文件中

测试和工作