WC_GZD_Gateway_Invoice

Pay by Invoice Gateway.

Defined (1)

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

/includes/gateways/invoice/class-wc-gzd-gateway-invoice.php  
  1. class WC_GZD_Gateway_Invoice extends WC_Payment_Gateway { 
  2.  
  3. /** 
  4. * Constructor for the gateway. 
  5. */ 
  6. public function __construct() { 
  7. $this->id = 'invoice'; 
  8. $this->icon = apply_filters( 'woocommerce_gzd_invoice_icon', '' ); 
  9. $this->has_fields = true; 
  10. $this->method_title = __( 'Pay by Invoice', 'woocommerce-germanized' ); 
  11. $this->method_description = __( 'Customers will be able to pay by invoice.', 'woocommerce-germanized' ); 
  12.  
  13. // Load the settings. 
  14. $this->init_form_fields(); 
  15. $this->init_settings(); 
  16.  
  17. // Define user set variables 
  18. $this->enabled = $this->get_option( 'enabled' ); 
  19. $this->title = $this->get_option( 'title' ); 
  20. $this->description = $this->get_option( 'description' ); 
  21. $this->instructions = $this->get_option( 'instructions', $this->description ); 
  22. $this->default_order_status = $this->get_option( 'default_order_status', 'on-hold' ); 
  23. $this->customers_only = $this->get_option( 'customers_only', 'no' ); 
  24. $this->customers_completed = $this->get_option( 'customers_completed', 'no' ); 
  25.  
  26. // Actions 
  27. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); 
  28. add_action( 'woocommerce_thankyou_invoice', array( $this, 'thankyou_page' ) ); 
  29.  
  30.  
  31. public function admin_options() { ?> 
  32.  
  33. <h3><?php echo ( ! empty( $this->method_title ) ) ? $this->method_title : __( 'Settings', 'woocommerce-germanized' ) ; ?></h3> 
  34.  
  35. <?php echo ( ! empty( $this->method_description ) ) ? wpautop( $this->method_description ) : ''; ?> 
  36.  
  37. <?php if ( ! WC_germanized()->is_pro() ) : ?> 
  38.  
  39. <div class="wc-gzd-premium-overlay notice notice-warning inline"> 
  40. <h3><?php _e( 'Automatically generate PDF invoices for this gateway?', 'woocommerce-germanized' );?></h3> 
  41. <p><?php _e( 'By upgrading to the professional version you\'ll be able to automatically generate PDF invoices to this payment gateway. Furthermore you\'ll benefit from even more professional features such as a multistep checkout page, legal text generators, B2B VAT settings and premium support!', 'woocommerce-germanized' );?></p> 
  42. <p> 
  43. <a class="button button-primary" href="https://vendidero.de/woocommerce-germanized" target="_blank"><?php _e( 'Upgrade now', 'woocommerce-germanized' ); ?></a> 
  44. <a class="button button-secondary" style="margin-left: 1em" href="https://vendidero.de/woocommerce-germanized#accounting" target="_blank"><?php _e( 'Learn more about PDF invoicing', 'woocommerce-germanized' ); ?></a> 
  45. </p> 
  46. </div> 
  47.  
  48. <?php endif; ?> 
  49.  
  50. <table class="form-table"> 
  51. <?php $this->generate_settings_html(); ?> 
  52. </table><?php 
  53.  
  54. /** 
  55. * Initialise Gateway Settings Form Fields 
  56. */ 
  57. public function init_form_fields() { 
  58.  
  59. $this->form_fields = array( 
  60. 'enabled' => array( 
  61. 'title' => __( 'Enable/Disable', 'woocommerce-germanized' ),  
  62. 'type' => 'checkbox',  
  63. 'label' => __( 'Enable Pay by Invoice', 'woocommerce-germanized' ),  
  64. 'default' => 'no' 
  65. ),  
  66. 'title' => array( 
  67. 'title' => _x( 'Title', 'gateway', 'woocommerce-germanized' ),  
  68. 'type' => 'text',  
  69. 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-germanized' ),  
  70. 'default' => __( 'Pay by Invoice', 'woocommerce-germanized' ),  
  71. 'desc_tip' => true,  
  72. ),  
  73. 'description' => array( 
  74. 'title' => __( 'Description', 'woocommerce-germanized' ),  
  75. 'type' => 'textarea',  
  76. 'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce-germanized' ),  
  77. 'default' => __( 'You\'ll receive an invoice after your order. Please transfer the order amount to our bank account within 14 days.', 'woocommerce-germanized' ),  
  78. 'desc_tip' => true,  
  79. ),  
  80. 'instructions' => array( 
  81. 'title' => __( 'Instructions', 'woocommerce-germanized' ),  
  82. 'type' => 'textarea',  
  83. 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce-germanized' ),  
  84. 'default' => '',  
  85. 'desc_tip' => true,  
  86. ),  
  87. 'default_order_status' => array( 
  88. 'title' => __( 'Order Status', 'woocommerce-germanized' ),  
  89. 'type' => 'select',  
  90. 'description' => __( 'Choose which order status should be applied after a customer has chosen to pay by invoice.', 'woocommerce-germanized' ),  
  91. 'default' => 'wc-on-hold',  
  92. 'options' => wc_get_order_statuses(),  
  93. 'desc_tip' => true,  
  94. ),  
  95. 'customers_only' => array( 
  96. 'title' => __( 'Registered customers', 'woocommerce-germanized' ),  
  97. 'label' => __( 'Do only offer pay by invoice to registered/logged in customers.', 'woocommerce-germanized' ),  
  98. 'type' => 'checkbox',  
  99. 'description' => __( 'This will enable Pay by Invoice to logged in customers only', 'woocommerce-germanized' ),  
  100. 'desc_tip' => true,  
  101. 'default' => 'no',  
  102. ),  
  103. 'customers_completed' => array( 
  104. 'title' => __( 'Customer limitation', 'woocommerce-germanized' ),  
  105. 'label' => __( 'Do only offer pay by invoice to customers who have at least completed one order.', 'woocommerce-germanized' ),  
  106. 'type' => 'checkbox',  
  107. 'default' => 'no',  
  108. ),  
  109. ); 
  110.  
  111. /** 
  112. * Output for the order received page. 
  113. */ 
  114. public function thankyou_page() { 
  115. if ( $this->instructions ) 
  116. echo wpautop( wptexturize( $this->instructions ) ); 
  117.  
  118. /** 
  119. * Add content to the WC emails. 
  120. * @access public 
  121. * @param WC_Order $order 
  122. * @param bool $sent_to_admin 
  123. * @param bool $plain_text 
  124. */ 
  125. public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { 
  126. if ( $this->instructions && ! $sent_to_admin && 'invoice' === $order->payment_method && $order->has_status( 'on-hold' ) ) { 
  127. echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; 
  128.  
  129. public function is_available() { 
  130.  
  131. if ( 'yes' != $this->enabled ) 
  132. return false; 
  133.  
  134. if ( is_checkout() ) { 
  135.  
  136. if ( $this->get_option( 'customers_only' ) == 'yes' && ! is_user_logged_in() ) 
  137. return false; 
  138.  
  139. if ( $this->get_option( 'customers_completed' ) == 'yes' && ( ! is_user_logged_in() || ! WC()->customer->is_paying_customer( get_current_user_id() ) ) ) 
  140. return false; 
  141.  
  142.  
  143. return true; 
  144.  
  145. /** 
  146. * Process the payment and return the result 
  147. * @param int $order_id 
  148. * @return array 
  149. */ 
  150. public function process_payment( $order_id ) { 
  151.  
  152. $order = wc_get_order( $order_id ); 
  153.  
  154. // Mark as on-hold (we're awaiting the cheque) 
  155. $order->update_status( $this->default_order_status ); 
  156.  
  157. // Reduce stock levels 
  158. $order->reduce_order_stock(); 
  159.  
  160. // Remove cart 
  161. WC()->cart->empty_cart(); 
  162.  
  163. // Return thankyou redirect 
  164. return array( 
  165. 'result' => 'success',  
  166. 'redirect' => $this->get_return_url( $order ) 
  167. );