WC_Gateway_Cheque

Cheque Payment Gateway.

Defined (1)

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

/includes/gateways/cheque/class-wc-gateway-cheque.php  
  1. class WC_Gateway_Cheque extends WC_Payment_Gateway { 
  2.  
  3. /** 
  4. * Constructor for the gateway. 
  5. */ 
  6. public function __construct() { 
  7. $this->id = 'cheque'; 
  8. $this->icon = apply_filters( 'woocommerce_cheque_icon', '' ); 
  9. $this->has_fields = false; 
  10. $this->method_title = _x( 'Check payments', 'Check payment method', 'woocommerce' ); 
  11. $this->method_description = __( 'Allows check payments. Why would you take checks in this day and age? Well you probably wouldn\'t but it does allow you to make test purchases for testing order emails and the \'success\' pages etc.', 'woocommerce' ); 
  12.  
  13. // Load the settings. 
  14. $this->init_form_fields(); 
  15. $this->init_settings(); 
  16.  
  17. // Define user set variables 
  18. $this->title = $this->get_option( 'title' ); 
  19. $this->description = $this->get_option( 'description' ); 
  20. $this->instructions = $this->get_option( 'instructions' ); 
  21.  
  22. // Actions 
  23. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); 
  24. add_action( 'woocommerce_thankyou_cheque', array( $this, 'thankyou_page' ) ); 
  25.  
  26. // Customer Emails 
  27. add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); 
  28.  
  29. /** 
  30. * Initialise Gateway Settings Form Fields. 
  31. */ 
  32. public function init_form_fields() { 
  33.  
  34. $this->form_fields = array( 
  35. 'enabled' => array( 
  36. 'title' => __( 'Enable/Disable', 'woocommerce' ),  
  37. 'type' => 'checkbox',  
  38. 'label' => __( 'Enable check payments', 'woocommerce' ),  
  39. 'default' => 'yes',  
  40. ),  
  41. 'title' => array( 
  42. 'title' => __( 'Title', 'woocommerce' ),  
  43. 'type' => 'text',  
  44. 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),  
  45. 'default' => _x( 'Check payments', 'Check payment method', 'woocommerce' ),  
  46. 'desc_tip' => true,  
  47. ),  
  48. 'description' => array( 
  49. 'title' => __( 'Description', 'woocommerce' ),  
  50. 'type' => 'textarea',  
  51. 'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ),  
  52. 'default' => __( 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'woocommerce' ),  
  53. 'desc_tip' => true,  
  54. ),  
  55. 'instructions' => array( 
  56. 'title' => __( 'Instructions', 'woocommerce' ),  
  57. 'type' => 'textarea',  
  58. 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce' ),  
  59. 'default' => '',  
  60. 'desc_tip' => true,  
  61. ),  
  62. ); 
  63.  
  64. /** 
  65. * Output for the order received page. 
  66. */ 
  67. public function thankyou_page() { 
  68. if ( $this->instructions ) 
  69. echo wpautop( wptexturize( $this->instructions ) ); 
  70.  
  71. /** 
  72. * Add content to the WC emails. 
  73. * @access public 
  74. * @param WC_Order $order 
  75. * @param bool $sent_to_admin 
  76. * @param bool $plain_text 
  77. */ 
  78. public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { 
  79. if ( $this->instructions && ! $sent_to_admin && 'cheque' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) { 
  80. echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; 
  81.  
  82. /** 
  83. * Process the payment and return the result. 
  84. * @param int $order_id 
  85. * @return array 
  86. */ 
  87. public function process_payment( $order_id ) { 
  88.  
  89. $order = wc_get_order( $order_id ); 
  90.  
  91. // Mark as on-hold (we're awaiting the cheque) 
  92. $order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) ); 
  93.  
  94. // Reduce stock levels 
  95. wc_reduce_stock_levels( $order_id ); 
  96.  
  97. // Remove cart 
  98. WC()->cart->empty_cart(); 
  99.  
  100. // Return thankyou redirect 
  101. return array( 
  102. 'result' => 'success',  
  103. 'redirect' => $this->get_return_url( $order ),  
  104. );