id, array( 'edit-shop_order', 'woocommerce_page_wc-orders' ), true ) ) { return; } // The HPOS order edit screen shares the list's screen id. // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only screen routing. if ( isset( $_GET['action'] ) && in_array( sanitize_key( wp_unslash( $_GET['action'] ) ), array( 'edit', 'new' ), true ) ) { return; } add_filter( 'woocommerce_get_formatted_order_total', array( $this, 'orders_list_full_total' ), 10, 4 ); } /** * Swap the deposit for the full order value while the list table is rendered. * * @param string $formatted_total Formatted total HTML. * @param WC_Order $order Order object. * @param string $tax_display Tax display mode. * @param bool $display_refunded Whether refunds are shown. * @return string */ public function orders_list_full_total( $formatted_total, $order, $tax_display = '', $display_refunded = true ) { // Bulk actions run before the page header and may send emails; leave those alone. if ( ! did_action( 'in_admin_header' ) || ! $order instanceof WC_Order || $order->get_total_refunded() ) { return $formatted_total; } if ( ! apply_filters( 'apd_display_full_order_total', true, $order ) || ! APD_Order::is_deposit_order( $order ) ) { return $formatted_total; } $total_amount = floatval( $order->get_meta( '_apd_total_amount' ) ); if ( $total_amount <= 0 ) { return $formatted_total; } return APD_Order::swap_in_full_total( (string) $formatted_total, $order, $total_amount ); } /** * Qualify the order items "Order Total" label on deposit orders. * * On a deposit order that total is the amount charged in the current payment, not the * order value, and WooCommerce prints the row with no hook of its own. The gettext * filter is added right before that row and removed right after the table, so it can * only ever touch this one label. * * @param int $order_id Order ID. */ public function start_order_total_label( $order_id ) { $order = wc_get_order( $order_id ); if ( ! $order || ! APD_Order::is_deposit_order( $order ) ) { return; } $full_total = floatval( $order->get_meta( '_apd_total_amount' ) ); if ( $full_total <= 0 || 0.0 === round( $full_total - (float) $order->get_total(), wc_get_price_decimals() ) ) { return; } $this->order_total_suffix = APD_Order::has_pending_balance_payment( $order ) ? __( 'Balance payment', 'advanced-partial-payment-or-deposit-for-woocommerce' ) : __( 'Deposit', 'advanced-partial-payment-or-deposit-for-woocommerce' ); add_filter( 'gettext_woocommerce', array( $this, 'filter_order_total_label' ), 10, 2 ); } /** * Append the deposit qualifier to WooCommerce's "Order Total" label. * * @param string $translation Translated text. * @param string $text Original text. * @return string */ public function filter_order_total_label( $translation, $text ) { if ( 'Order Total' !== $text || '' === $this->order_total_suffix ) { return $translation; } return sprintf( '%s (%s)', $translation, $this->order_total_suffix ); } /** * Show the full order value, paid amount and balance under the order items totals. * * @param int $order_id Order ID. */ public function render_order_totals_deposit_rows( $order_id ) { remove_filter( 'gettext_woocommerce', array( $this, 'filter_order_total_label' ), 10 ); $this->order_total_suffix = ''; $order = wc_get_order( $order_id ); $details = $order ? APD_Order::get_deposit_details( $order ) : false; if ( ! $details ) { return; } $currency = array( 'currency' => $order->get_currency() ); $rows = array( array( __( 'Full Order Total', 'advanced-partial-payment-or-deposit-for-woocommerce' ), $details['total_amount'], 'label label-highlight' ), array( __( 'Deposit Amount', 'advanced-partial-payment-or-deposit-for-woocommerce' ), $details['deposit_amount'], 'label' ), array( __( 'Total Paid', 'advanced-partial-payment-or-deposit-for-woocommerce' ), $details['amount_paid'], 'label' ), array( __( 'Balance Due', 'advanced-partial-payment-or-deposit-for-woocommerce' ), $details['balance_due'], 'label' ), ); foreach ( $rows as $row ) { ?>
' . esc_html__( 'This is not a deposit order.', 'advanced-partial-payment-or-deposit-for-woocommerce' ) . '
'; if ( APD_Admin_Order_Deposit::is_enabled() && APD_Admin_Order_Deposit::can_add_deposit( $order ) ) { APD_Admin_Order_Deposit::render_form( $order ); } return; } $details = APD_Order::get_deposit_details( $order ); if ( ! $details ) { return; } $can_edit_deposit = APD_Admin_Order_Deposit::is_enabled() && APD_Admin_Order_Deposit::can_edit_deposit( $order ); $paid_color = $details['amount_paid'] > 0 ? '#00a32a' : '#646970'; // Suggest what is actually due next: the balance, or a payment plan's next instalment. $manual_amount_due = ! empty( $details['deposit_paid'] ) ? APD_Order::get_balance_amount_due_now( $order ) : min( $details['deposit_amount'], $details['balance_due'] ); ?> get_order_object( $post_or_order ); if ( ! $order || ! APD_Order::is_deposit_order( $order ) ) { echo '' . esc_html__( 'No deposit payment record available for this order.', 'advanced-partial-payment-or-deposit-for-woocommerce' ) . '
'; return; } $details = APD_Order::get_deposit_details( $order ); if ( ! $details ) { echo '' . esc_html__( 'No payment record found.', 'advanced-partial-payment-or-deposit-for-woocommerce' ) . '
'; return; } $history = is_array( $details['history'] ) ? $details['history'] : array(); $running_total = 0; $paid_color = $details['amount_paid'] > 0 ? '#00a32a' : '#646970'; ?>| get_payment_type_label( $entry ) ); ?> | ||||||