From 8e499c9c954414de37cf0431fcaaee1b6a1437d2 Mon Sep 17 00:00:00 2001 From: Patrick Garman Date: Wed, 11 Jan 2012 20:44:10 +0000 Subject: [PATCH] Adding Cash on Delivery Gateway --- classes/gateways/gateway-cod.php | 97 ++++++++++++++++++++++++++++++++ woocommerce.php | 1 + 2 files changed, 98 insertions(+) create mode 100644 classes/gateways/gateway-cod.php diff --git a/classes/gateways/gateway-cod.php b/classes/gateways/gateway-cod.php new file mode 100644 index 00000000000..a6b650a1e5f --- /dev/null +++ b/classes/gateways/gateway-cod.php @@ -0,0 +1,97 @@ +method_title = 'Cash on Delivery'; + $this->id = 'cod'; + + // Load the form fields. + $this->init_form_fields(); + + // Load the settings. + $this->init_settings(); + + // Define user set variables + $this->title = $this->settings['title']; + $this->description = $this->settings['description']; + $this->instructions = $this->settings['instructions']; + + add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options')); + add_action('woocommerce_thankyou_cod', array(&$this, 'thankyou')); + } + + function admin_options() { + ?> +

+

+ + generate_settings_html(); ?> +
form_fields = array( + 'enabled' => array( + 'title' => __( 'Enable COD', 'woocommerce' ), + 'label' => __( 'Turn on Cash on Delivery for WooCommerce', 'woocommerce' ), + 'type' => 'checkbox', + 'description' => '', + 'default' => 'no' + ), + 'title' => array( + 'title' => __( 'Title', 'woocommerce' ), + 'type' => 'text', + 'description' => __( 'Payment method title that the customer will see on your website.', 'woocommerce' ), + 'default' => __( 'Cash on Delivery', 'woocommerce' ) + ), + 'description' => array( + 'title' => __( 'Description', 'woocommerce' ), + 'type' => 'textarea', + 'description' => __( 'Payment method description that the customer will see on your website.', 'woocommerce' ), + 'default' => 'Pay with cash upon delivery.' + ), + 'instructions' => array( + 'title' => __( 'Instructions', 'woocommerce' ), + 'type' => 'textarea', + 'description' => __( 'Instructions that will be added to the thank you page.', 'woocommerce' ), + 'default' => 'Pay with cash upon delivery.' + ), + ); + } + + function payment_fields() { // Fields for the payment form + if ($this->description) { echo '

'.$this->description.'

'; } + } + + // Process the payment + function process_payment ($order_id) { + global $woocommerce; + $order = &new woocommerce_order ($order_id); + $order->update_status('on-hold', __('Payment to be made upon delivery.', 'woocommerce')); + $woocommerce->cart->empty_cart(); // Dump the cart + unset($_SESSION['order_awaiting_payment']); // Lose our session + return array( // Return and let's visit the order completed page + 'result' => 'success', + 'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(get_option('woocommerce_thanks_page_id')))) + ); + } + + function thankyou() { + if ($this->instructions!='') { echo '

'.$this->instructions.'

'; } + } + +} + +// Adding Gateway to WooCommerce Gateways +function woocommerce_cod_add_gateway ($methods) { $methods[] = 'woocommerce_cod'; return $methods; } +add_filter ('woocommerce_payment_gateways', 'woocommerce_cod_add_gateway'); \ No newline at end of file diff --git a/woocommerce.php b/woocommerce.php index 334b0e9fd74..395a89850b0 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -182,6 +182,7 @@ class woocommerce { include( 'classes/gateways/gateway-banktransfer.php' ); include( 'classes/gateways/gateway-cheque.php' ); include( 'classes/gateways/gateway-paypal.php' ); + include( 'classes/gateways/gateway-cod.php' ); } /**