gpt4 book ai didi

php - WooCommerce - 调整折扣和退款的客户生命周期订单成本

转载 作者:行者123 更新时间:2023-12-04 04:14:41 26 4
gpt4 key购买 nike

我试图吐出客户总(已完成)订单的生命周期成本。如果他们没有打折,我得到的值(value)等于金额,但是我已经将所有订单打折到 0 美元,因此如果他们根本没有支付任何钱,我使用这些数据是非常误导的。在对该订单应用退款和折扣后,我如何才能获得他们实际支付的值(value)?

function get_customer_total_order() {
$customer_orders = get_posts( array(
'numberposts' => - 1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => array( 'shop_order' ),
'post_status' => array( 'wc-completed' )
) );

$total = 0;
foreach ( $customer_orders as $customer_order ) {
$order = wc_get_order( $customer_order );
$total += $order->get_total();
}

return $total;
}

最佳答案

这是我的最终功能:

// Get customer order total
function has_refunds( $order ) {
return sizeof( $order->get_refunds() ) > 0 ? true : false;
}
function get_customer_total_order() {
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => array( 'shop_order' ),
'post_status' => array( 'wc-completed' )
) );

$total = 0;
foreach ( $customer_orders as $customer_order ) {
$order = wc_get_order( $customer_order );

if( has_refunds( $order ) ) {
}
else
{
$price = $order->get_total();

$discount = $order->get_total_discount();

$final = $price - $discount;

$total += $final;
}

}

return $total;
}

关于php - WooCommerce - 调整折扣和退款的客户生命周期订单成本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60962905/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com