2 回答

TA貢獻1858條經(jīng)驗 獲得超8個贊
您的代碼中有很多錯誤,例如:
在短代碼中,顯示永遠不會回顯而是返回,
WC_Cart
?get_product_price()
方法顯示格式化的產(chǎn)品價格僅用于顯示,_要檢查購物車項目上的產(chǎn)品類別,請始終使用 $cart_item['product_id'] 代替...
所以嘗試一下:
add_shortcode( 'quote-total', 'get_quote_total' );
function get_quote_total(){
? ? $total? ? ? ? = WC()->cart->total;
? ? $disbursement = 0; // Initializng
? ??
? ? // Loop through cart items
? ? foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
? ? ? ? if ( has_term( array('funeral-types-new'), 'product_cat', $cart_item['product_id'] ) ) {
? ? ? ? ? ? $disbursement += $cart_item['line_total'] + $cart_item['line_tax'];
? ? ? ? }
? ? }
? ??
? ? $subtotal = $total - $disbursement;
? ??
? ? return '<div>'.wc_price($subtotal).'</div><div> + '.wc_price($disbursement).'</div>';
}
// USAGE: [quote-total]?
//? ? or: echo do_shortcode('[quote-total]');
它應該更好地工作。
- 2 回答
- 0 關注
- 212 瀏覽
添加回答
舉報