2012-01-12 00:54:45 +00:00
< ? php
/**
* Cheque Payment Gateway
2012-08-15 18:15:06 +00:00
*
2012-01-12 00:54:45 +00:00
* Provides a Cheque Payment Gateway , mainly for testing purposes .
*
2012-01-27 16:38:39 +00:00
* @ class WC_Cheque
2012-08-15 18:15:06 +00:00
* @ extends WC_Payment_Gateway
* @ version 1.6 . 4
* @ package WooCommerce / Classes / Payment
* @ author WooThemes
2012-01-12 00:54:45 +00:00
*/
2012-10-15 10:57:58 +00:00
if ( ! defined ( 'ABSPATH' ) ) exit ; // Exit if accessed directly
2012-01-27 16:38:39 +00:00
class WC_Cheque extends WC_Payment_Gateway {
2012-08-15 18:15:06 +00:00
/**
* Constructor for the gateway .
*
* @ access public
* @ return void
*/
public function __construct () {
2012-01-12 00:54:45 +00:00
$this -> id = 'cheque' ;
$this -> icon = apply_filters ( 'woocommerce_cheque_icon' , '' );
$this -> has_fields = false ;
2012-01-31 12:35:01 +00:00
$this -> method_title = __ ( 'Cheque' , 'woocommerce' );
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
// Load the settings.
$this -> init_settings ();
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
// Define user set variables
2012-12-31 12:07:43 +00:00
$this -> title = $this -> get_option ( 'title' );
$this -> description = $this -> get_option ( 'description' );
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
// Actions
2012-12-15 11:53:32 +00:00
add_action ( 'woocommerce_update_options_payment_gateways' , array ( $this , 'process_admin_options' ) );
add_action ( 'woocommerce_thankyou_cheque' , array ( $this , 'thankyou_page' ) );
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
// Customer Emails
2012-12-15 11:53:32 +00:00
add_action ( 'woocommerce_email_before_order_table' , array ( $this , 'email_instructions' ), 10 , 2 );
2012-08-15 18:15:06 +00:00
}
/**
2012-01-12 00:54:45 +00:00
* Initialise Gateway Settings Form Fields
2012-08-15 18:15:06 +00:00
*
* @ access public
* @ return void
2012-01-12 00:54:45 +00:00
*/
function init_form_fields () {
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
$this -> form_fields = array (
'enabled' => array (
2012-08-15 18:15:06 +00:00
'title' => __ ( 'Enable/Disable' , 'woocommerce' ),
'type' => 'checkbox' ,
'label' => __ ( 'Enable Cheque Payment' , 'woocommerce' ),
2012-01-12 00:54:45 +00:00
'default' => 'yes'
2012-08-15 18:15:06 +00:00
),
2012-01-12 00:54:45 +00:00
'title' => array (
2012-08-15 18:15:06 +00:00
'title' => __ ( 'Title' , 'woocommerce' ),
'type' => 'text' ,
'description' => __ ( 'This controls the title which the user sees during checkout.' , 'woocommerce' ),
2012-01-12 00:54:45 +00:00
'default' => __ ( 'Cheque Payment' , 'woocommerce' )
),
'description' => array (
2012-08-15 18:15:06 +00:00
'title' => __ ( 'Customer Message' , 'woocommerce' ),
'type' => 'textarea' ,
'description' => __ ( 'Let the customer know the payee and where they should be sending the cheque to and that their order won\'t be shipping until you receive it.' , 'woocommerce' ),
'default' => __ ( 'Please send your cheque to Store Name, Store Street, Store Town, Store State / County, Store Postcode.' , 'woocommerce' )
2012-01-12 00:54:45 +00:00
)
);
2012-08-15 18:15:06 +00:00
}
2012-01-12 00:54:45 +00:00
/**
2012-08-15 18:15:06 +00:00
* Admin Panel Options
2012-01-12 00:54:45 +00:00
* - Options for bits like 'title' and availability on a country - by - country basis
*
2012-08-15 18:15:06 +00:00
* @ access public
* @ return void
2012-01-12 00:54:45 +00:00
*/
public function admin_options () {
?>
2012-10-16 09:45:33 +00:00
< h3 >< ? php _e ( 'Cheque Payment' , 'woocommerce' ); ?> </h3>
< p >< ? php _e ( 'Allows cheque payments. Why would you take cheques 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' ); ?> </p>
2012-01-12 00:54:45 +00:00
< table class = " form-table " >
< ? php
// Generate the HTML For the settings form.
$this -> generate_settings_html ();
?>
</ table ><!--/. form - table -->
< ? php
2012-08-15 18:15:06 +00:00
}
/**
* Output for the order received page .
*
* @ access public
* @ return void
*/
2012-01-12 00:54:45 +00:00
function thankyou_page () {
2012-08-15 18:15:06 +00:00
if ( $description = $this -> get_description () )
2012-06-29 18:44:33 +00:00
echo wpautop ( wptexturize ( $description ) );
2012-01-12 00:54:45 +00:00
}
2012-08-15 18:15:06 +00:00
/**
* Add content to the WC emails .
*
* @ access public
* @ param WC_Order $order
* @ param bool $sent_to_admin
* @ return void
*/
2012-01-12 00:54:45 +00:00
function email_instructions ( $order , $sent_to_admin ) {
if ( $sent_to_admin ) return ;
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
if ( $order -> status !== 'on-hold' ) return ;
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
if ( $order -> payment_method !== 'cheque' ) return ;
2012-08-15 18:15:06 +00:00
if ( $description = $this -> get_description () )
2012-06-29 18:44:33 +00:00
echo wpautop ( wptexturize ( $description ) );
2012-01-12 00:54:45 +00:00
}
2012-08-15 18:15:06 +00:00
/**
* Process the payment and return the result
*
* @ access public
* @ param int $order_id
* @ return array
*/
2012-01-12 00:54:45 +00:00
function process_payment ( $order_id ) {
2012-01-12 00:43:30 +00:00
global $woocommerce ;
2012-01-12 00:54:45 +00:00
2012-01-27 16:38:39 +00:00
$order = new WC_Order ( $order_id );
2012-01-12 00:54:45 +00:00
// Mark as on-hold (we're awaiting the cheque)
2012-10-16 09:45:33 +00:00
$order -> update_status ( 'on-hold' , __ ( 'Awaiting cheque payment' , 'woocommerce' ));
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
// Reduce stock levels
$order -> reduce_order_stock ();
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
// Remove cart
$woocommerce -> cart -> empty_cart ();
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
// Return thankyou redirect
return array (
'result' => 'success' ,
'redirect' => add_query_arg ( 'key' , $order -> order_key , add_query_arg ( 'order' , $order_id , get_permalink ( woocommerce_get_page_id ( 'thanks' ))))
);
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
}
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
}
2012-08-15 18:15:06 +00:00
2012-01-12 00:54:45 +00:00
/**
* Add the gateway to WooCommerce
2012-08-15 18:15:06 +00:00
*
* @ access public
* @ param array $methods
* @ package WooCommerce / Classes / Payment
* @ return array
*/
2012-01-12 00:54:45 +00:00
function add_cheque_gateway ( $methods ) {
2012-08-15 18:15:06 +00:00
$methods [] = 'WC_Cheque' ;
return $methods ;
2012-01-12 00:54:45 +00:00
}
2012-08-15 18:15:06 +00:00
add_filter ( 'woocommerce_payment_gateways' , 'add_cheque_gateway' );