【问题标题】:Woocommerce Short_Description in Details OrderWoocommerce Short_Description in Details Order
【发布时间】:2017-12-20 14:32:10
【问题描述】:

我正在使用 Wordpress 和 Woocommerce 创建我的新网站。我想在订单详情中显示简短描述。

我找到了这段代码:

add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_single_excerpt', 5);

但这显示了我在家里的描述。

有没有办法让它出现在订单详情中?

【问题讨论】:

  • 我觉得有必要说 Stack Overflow 不是一个“论坛”,而是一个基于事实的问答平台。您可以在“论坛”上找到关于编程问题的持续讨论。

标签: php wordpress woocommerce hook-woocommerce orders


【解决方案1】:

这可以通过在woocommerce_order_item_name 过滤器钩子中挂钩的自定义函数来完成,这样:

add_filter( 'woocommerce_order_item_name', 'add_single_excerpt_to_order_item', 10, 3 );
function add_single_excerpt_to_order_item( $item_name, $item, $is_visible ){
    $product_id = $item->get_product_id(); // Get the product Id
    $excerpt = get_the_excerpt( $product_id ); // Get the short description

    return $item_name . '<br><p class="item-description">' . $excerpt ; '</p>';
}

此代码位于您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。

经过测试并且有效。它将在项目名称下方的订单项目中显示简短描述。

【讨论】:

  • 非常感谢您的帮助。我已经测试了代码并且效果很好。我不知道如何还款,我可以向网站或其他地方捐款吗?再次感谢
  • 如果这个答案对你有用,那么就给这个答案投票,让这个答案正确。以便其他人可以使用它。
猜你喜欢
  • 1970-01-01
  • 2010-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多