![](/img/trans.png)
[英]Display product (variation) description in a new line on WooCommerce order received page and emails
[英]Woocommerce: Display Product Variation Description on order page
我正在嘗試在訂單詳細信息頁面和訂單電子郵件中顯示產品變體描述。 遵循此示例Woocommerce:在購物車頁面上顯示產品變體描述它非常適合購物車和結帳。 但似乎我找不到為訂單頁面調用它的正確方法。
這個
$item = $cart_item['data'];
if(!empty($item) && $item->is_type( 'variation' ) ){
echo '<dl><dd>' . $item->get_variation_description() }
不工作,因為它要求購物車項目數據..和這里建議的 get_post_meta WooCommerce 在可變價格后顯示變量描述也不起作用。
$_variable_description = get_post_meta( $variation->id , '_variation_description', true );
我試圖將它放在order-details-item.php和class-wc-order-item-meta.php 中,當然還有email-order-details.php
有什么建議? 謝謝!
我終於找到了一個在這里工作的解決方案,現在在訂單頁面和訂單電子郵件上顯示變體描述。
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 ;
}
它將變體描述放在標題正下方,但這對我有用。
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中試試這個
終於找到了一個有效的解決方案問題解決了,將其添加到子主題 function.php 中:
add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.