【问题标题】:Woocommerce: Display Product Variation Description on order pageWoocommerce:在订单页面上显示产品变化描述
【发布时间】:2017-07-17 05:51:40
【问题描述】:

我正在尝试在订单详情页面和订单电子邮件中显示产品变体描述。按照这个例子Woocommerce: Display Product Variation Description on Cart page 它非常适合购物车和结帐。但似乎我找不到在订单页面调用它的正确方法。

这个

$item = $cart_item['data'];
if(!empty($item) && $item->is_type( 'variation' ) ){
    echo '<dl><dd>' . $item->get_variation_description() }

不工作,因为它需要购物车项目数据.. 并且这里建议的 get_post_meta WooCommerce displaying variable description after variable price 也不起作用。

$_variable_description = get_post_meta( $variation->id , '_variation_description', true );

我尝试将它放在 order-details-item.phpclass-wc-order-item-meta.php 中,当然还有email-order-details.php

有什么建议吗?谢谢!

【问题讨论】:

    标签: php email woocommerce orders variations


    【解决方案1】:

    大约 5 年后,这仍然有效,这正是我正在建造的面包店网站所需要的。

    我使用了这个组合(以防其他人出现):

    function display_product_title_as_link( $item_name, $item ) {
    
        $_product = get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );
    
        $link = get_permalink( $_product->id );
    
        $_var_description ='';
    
        if ( $item['variation_id'] ) {
            $_var_description = $_product->get_variation_description();
        }
    
        return '<a href="'. $link .'"  rel="nofollow">'. $item_name .'</a><br>'. $_var_description ;
    }
    
    add_filter( 'woocommerce_product_variation_title_include_attributes','__return_false' );
    

    非常感谢能够在这里找到答案。

    【讨论】:

      【解决方案2】:

      终于找到了可行的解决方案 问题解决了,添加到子主题function.php中:

      add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );
      

      【讨论】:

        【解决方案3】:

        我终于找到了一个有效的解决方案 here 现在在订单页面和订单电子邮件上显示变体描述。

        add_filter( 'woocommerce_order_item_name', 'display_product_title_as_link', 10, 2 );
        function display_product_title_as_link( $item_name, $item ) {
        
            $_product = get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );
        
            $link = get_permalink( $_product->id );
        
            $_var_description ='';
        
            if ( $item['variation_id'] ) {
                $_var_description = $_product->get_variation_description();
            }
        
            return '<a href="'. $link .'"  rel="nofollow">'. $item_name .'</a><br>'. $_var_description ;
        }
        

        它将变体描述放在标题的正下方,但这对我有用。

        【讨论】:

          【解决方案4】:
          add_filter( 'woocommerce_order_item_name', 'display_product_description', 10, 2 );
              function display_product_description( $item_name, $item ) {
          
                  $_product = get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );
          
          
                  $_var_description ='';
          
                  if ( $item['variation_id'] ) {
                      $_var_description = $_product->get_variation_description();
                  }
          
                  return $_var_description ;
              }
          

          在你主题的functions.php中试试这个

          【讨论】:

          • 它有效,因为它现在在订单页面和电子邮件上显示变体描述。但是现在它显示的是描述而不是产品的名称..
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-09-18
          • 1970-01-01
          • 2021-06-25
          • 2020-02-24
          • 1970-01-01
          • 2018-07-11
          • 1970-01-01
          相关资源
          最近更新 更多