我正在使用woocommerce和「打印發票&包裝清單」 可在「https://woocommerce.com/products/print-invoices-packing-lists/」處獲得。 用於顯示的總儲蓄在woocommerce車&結帳頁面,我用這個代碼和完美的作品:WooCommerce - 在訂單循環中轉置購物車循環以獲得pdf發票
function bbloomer_wc_discount_total() {
global $woocommerce;
$cart_subtotal = $woocommerce->cart->cart_contents;
$discount_total = 0;
foreach ($woocommerce->cart->cart_contents as $product_data) {
if ($product_data['variation_id'] > 0) {
$product = wc_get_product($product_data['variation_id']);
} else {
$product = wc_get_product($product_data['product_id']);
}
if (!empty($product->sale_price)) {
$discount = ($product->regular_price - $product->sale_price) * $product_data['quantity'];
$discount_total += $discount;
}
}
if ($discount_total > 0) {
echo '<tr class="cart-discount">
<th>'. __('Total Saving :', 'woocommerce') .'</th>
<td data-title=" '. __('Total Saving :', 'woocommerce') .' ">'
. wc_price($discount_total+$woocommerce->cart->discount_cart) .'</td>
</tr>';
}
}
add_action('woocommerce_cart_totals_after_order_total', 'bbloomer_wc_discount_total');
add_action('woocommerce_review_order_after_order_total', 'bbloomer_wc_discount_total');
總部設在woocommerce車的內容,此功能。 我如何可以顯示打印發票產生的總儲蓄在HTML發票&包裝列出了插件鉤子插件(根據訂單,而不是車的內容),如:
add_action('wc_pip_after_header', 'bbloomer_wc_discount_total'); add_action('wc_pip_document_header', 'bbloomer_wc_discount_total');
感謝您的回覆。 我已將此代碼添加到我的模板中的functions.php中,並使用Woocommerce pip插件,然後在html發票頁面中顯示:致命錯誤:調用布爾型成員函數get_items() – Mani
嗨,非常感謝爲了您的迴應,我使用「WooCommerce打印發票和裝箱清單」,這是我可以下載的插件:https://www.dropbox.com/s/7mmsuh7o0tjaa45/woocommerce-pip.zip?dl=0和這是Hooks refrence:https://docs.woocommerce.com/document/woocommerce-print-invoices-packing-lists-developer-reference/。什麼代碼我可以添加到我的functions.php來顯示在Html發票總儲蓄?非常感謝你 ! – Mani
非常感謝,我可以將您的代碼添加到我的functions.php中。我如何使用你的代碼?謝謝 – Mani