payment_complete

The WooCommerce Billogram Integration payment complete function.

Description

payment_complete( $order, (string) $transaction_id = '' ); 

Parameters (2)

0. $order
The order.
1. $transaction_id — Optional. (string) => ''
The transaction id.

Usage

  1. if ( !function_exists( 'payment_complete' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-billogram-integration/woocommerce-billogram2-extended.php'; 
  3.  
  4. // The order. 
  5. $order = null; 
  6.  
  7. // The transaction id. 
  8. $transaction_id = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = payment_complete($order, $transaction_id); 
  12.  

Defined (1)

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

/woocommerce-billogram2-extended.php  
  1. function payment_complete( $order, $transaction_id = '' ) {  
  2. $options = get_option('woocommerce_billogram_general_settings'); 
  3. do_action( 'woocommerce_pre_payment_complete', $order->id ); 
  4. if ( null !== WC()->session ) { 
  5. WC()->session->set( 'order_awaiting_payment', false ); 
  6. $valid_order_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment_complete', array( 'on-hold', 'pending', 'failed', 'cancelled' ), $order ); 
  7. if ( $order->id && $order->has_status( $valid_order_statuses ) ) { 
  8. $order_needs_processing = true; 
  9. if ( sizeof( $order->get_items() ) > 0 ) { 
  10. foreach ( $order->get_items() as $item ) { 
  11. if ( $item['product_id'] > 0 ) { 
  12. $_product = $order->get_product_from_item( $item ); 
  13. if ( false !== $_product && ! apply_filters( 'woocommerce_order_item_needs_processing', ! ( $_product->is_downloadable() && $_product->is_virtual() ), $_product, $order->id ) ) { 
  14. $order_needs_processing = false; 
  15. continue; 
  16. $order_needs_processing = true; 
  17. break; 
  18. $new_order_status = $order_needs_processing ? 'processing' : 'completed'; 
  19. $new_order_status = apply_filters( 'woocommerce_payment_complete_order_status', $new_order_status, $order->id ); 
  20. $order->update_status( $new_order_status ); 
  21. add_post_meta( $order->id, '_paid_date', current_time('mysql'), true ); 
  22. if ( ! empty( $transaction_id ) ) { 
  23. add_post_meta( $order->id, '_transaction_id', $transaction_id, true ); 
  24. $this_order = array( 
  25. 'ID' => $order->id,  
  26. 'post_date' => current_time( 'mysql', 0 ),  
  27. 'post_date_gmt' => current_time( 'mysql', 1 ) 
  28. ); 
  29. wp_update_post( $this_order ); 
  30. if ( apply_filters( 'woocommerce_payment_complete_reduce_order_stock', true, $order->id ) ) { 
  31. if($options['stock-reduction'] == 'invoice') { 
  32. $order->reduce_order_stock(); // Payment is complete so reduce stock levels 
  33. do_action( 'woocommerce_payment_complete', $order->id ); 
  34. } else { 
  35. do_action( 'woocommerce_payment_complete_order_status_' . $order->get_status(), $order->id );