1 回答

TA貢獻1777條經(jīng)驗 獲得超3個贊
在email-order-items.php模板中,wc_display_item_meta()使用了函數(shù)。
如果我們進一步看,我們會看到這個函數(shù)在wc-template-functions.php
https://github.com/woocommerce/woocommerce/blob/master/includes/wc-template-functions.php
所以我們可以通過鉤子覆蓋輸出woocommerce_display_item_meta,通過參數(shù)我們可以獲得關(guān)于產(chǎn)品的必要信息。
function filter_woocommerce_display_item_meta ( $html, $item, $args ) {
// Get product
$product = $item->get_product();
// Html
if ( $product->backorders_require_notification() && $product->is_on_backorder( $item['quantity'] ) ) {
$html = '<ul class="wc-item-meta"><li><strong class="wc-item-meta-label" style="float: left; margin-right: .25em; clear: both">Made-To-Order</strong></li></ul>';
} else if ( !$product->backorders_require_notification() && !$product->is_on_backorder( $item['quantity'] ) ) {
$html = '<ul class="wc-item-meta"><li><strong class="wc-item-meta-label" style="float: left; margin-right: .25em; clear: both">Made-To-Order</strong></li></ul>';
} else {
$html = '<ul class="wc-item-meta"><li><strong class="wc-item-meta-label" style="float: left; margin-right: .25em; clear: both">In stock</strong></li></ul>';
}
return $html;
}
add_filter( 'woocommerce_display_item_meta', 'filter_woocommerce_display_item_meta', 10, 3 );
提示:為了使輸出更加動態(tài),您可以通過 args 重寫輸出(您可以在 中看到這是如何完成的wc-template-functions.php)
- 1 回答
- 0 關(guān)注
- 129 瀏覽
添加回答
舉報