我正在使用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