wc_order_fully_refunded

When refunding an order, create a refund line item if the partial refunds do not match order total.

Description

wc_order_fully_refunded( (int) $order_id ); 

This is manual; no gateway refund will be performed.

Parameters (1)

0. $order_id (int)
The order id.

Usage

  1. if ( !function_exists( 'wc_order_fully_refunded' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php'; 
  3.  
  4. // The order id. 
  5. $order_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_order_fully_refunded($order_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-order-functions.php  
  1. function wc_order_fully_refunded( $order_id ) { 
  2. $order = wc_get_order( $order_id ); 
  3. $max_refund = wc_format_decimal( $order->get_total() - $order->get_total_refunded() ); 
  4.  
  5. if ( ! $max_refund ) { 
  6. return; 
  7.  
  8. // Create the refund object 
  9. wc_create_refund( array( 
  10. 'amount' => $max_refund,  
  11. 'reason' => __( 'Order fully refunded', woocommerce ),  
  12. 'order_id' => $order_id,  
  13. 'line_items' => array(),  
  14. ) );