【发布时间】:2022-01-08 20:42:46
【问题描述】:
我编写的这段代码在 WooCommerce 结帐页面上显示个性化信息。
add_action( 'woocommerce_cart_totals_after_order_total', 'show_total_discount_cart_checkout', 9999 );
add_action( 'woocommerce_review_order_after_order_total', 'show_total_discount_cart_checkout', 9999 );
function show_total_discount_cart_checkout() {
$discount_total = 0;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
$subtotal = WC()->cart->get_product_subtotal( $product, $cart_item['quantity'] );
$total = WC()->cart->total;
$pctm = 90.00;
$valor_descontado = $total - ($total / 100 * $pctm);
$sale_price = '10%';
$discount = ( WC()->cart->total - $valor_descontado );
$discount_total = $discount;
}
if ( $discount_total > 0 ) {
echo '<tr><th>VOCÊ RECEBERÁ DE CASHBACK:</th><td data-title="You">' . wc_price( $discount_total + WC()->cart->get_discount_total() ) .'</td></tr>';
}
}
结果:
我需要此信息也显示在 WooCommerce 订单和电子邮件中。我相信我可以自己想出一个解决方案来在其他几个页面上显示这个值,但是有人可以先告诉我如何保存/存储这个计算的值吗?
【问题讨论】:
标签: wordpress woocommerce checkout orders email-notifications