1 回答

TA貢獻1811條經(jīng)驗 獲得超5個贊
你可以用
woocommerce_cart_item_subtotal
鉤子代替。foreach
不需要使用循環(huán)請注意 WooCommerce條件標簽的使用:
is_checkout()
- 在結賬頁面返回 true可選:
$cart_item['quantity'];
必要時可根據(jù)產(chǎn)品數(shù)量提供附加條件
function filter_woocommerce_cart_item_subtotal( $subtotal, $cart_item, $cart_item_key ) {
? ? // Returns true on the checkout page
? ? if ( is_checkout() ) {??
? ? ? ? ?// Item price title
? ? ? ? $price_title = 'Item price';
? ? ? ??
? ? ? ? // Item price
? ? ? ? $item_price = $cart_item['data']->get_price();
? ? ? ??
? ? ? ? // Line subtotal
? ? ? ? $line_subtotal = $cart_item['line_subtotal'];
? ? ? ??
? ? ? ? // Item title + item price
? ? ? ? $subtotal = '<span>' . $price_title . '</span>' . wc_price( $item_price );
? ? ? ??
? ? ? ? // Append to
? ? ? ? $subtotal .= wc_price( $line_subtotal );
? ? }
? ? return $subtotal;
}
add_filter( 'woocommerce_cart_item_subtotal', 'filter_woocommerce_cart_item_subtotal', 10, 3 );
- 1 回答
- 0 關注
- 130 瀏覽
添加回答
舉報