├── readme.md ├── screenshots ├── offline-gateway-checkout.png ├── offline-gateway-settings.png └── offline-gateway-thankyou.png └── woocommerce-gateway-offline.php /readme.md: -------------------------------------------------------------------------------- 1 | === WooCommerce Offline Gateway === 2 | 3 | - Contributors: skyverge, beka.rice 4 | - Tags: woocommerce, payment gateway, gateway, manual payment 5 | - [Donate link](https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal@skyverge.com&item_name=Donation+for+WooCommerce+Offline+Gateway) 6 | - Requires at least: 3.8 7 | - Tested up to: 4.3 8 | - Requires WooCommerce at least: 2.1 9 | - Tested WooCommerce up to: 2.4 10 | - Stable Tag: 1.0.1 11 | - License: GPLv3 12 | - License URI: http://www.gnu.org/licenses/gpl-3.0.html 13 | 14 | Automatically generate WooCommerce product SKUs from the product slug and/or variation attributes. 15 | 16 | == Description == 17 | 18 | > **Requires: WooCommerce 2.1+** 19 | 20 | This plugin clones the Cheque gateway to create another offline payment method. This can be used to create a testing payment method if you use the Cheque gateway for something else. For example, this could be used for manual invoices or other offline payment methods. 21 | 22 | When an order is submitted via the Offline payment method, the order will be placed "on-hold". 23 | 24 | = More Details = 25 | - See the [product page](http://www.skyverge.com/product/woocommerce-offline-gateway/) for full details and documentation 26 | - View more of SkyVerge's [free WooCommerce extensions](http://profiles.wordpress.org/skyverge/) 27 | - View all [SkyVerge WooCommerce extensions](http://www.skyverge.com/shop/) 28 | 29 | == Installation == 30 | 31 | 1. Be sure you're running WooCommerce 2.1+ in your shop. 32 | 2. You can: (1) upload the entire `woocommerce-gateway-offline` folder to the `/wp-content/plugins/` directory, (2) upload the .zip file with the plugin under **Plugins > Add New > Upload** 33 | 3. Activate the plugin through the **Plugins** menu in WordPress 34 | 4. Go to **WooCommerce > Settings > Checkout** and select "Offline" to configure 35 | 36 | == Frequently Asked Questions == 37 | 38 | **What is the text domain for translations?** 39 | The text domain is `wc-gateway-offline`. 40 | 41 | **Can I fork this?** 42 | Please do! This is meant to be a simple starter offline gateway, and can be modified easily. 43 | 44 | == Changelog == 45 | 46 | = 2015.07.27 - version 1.0.1 = 47 | * Misc: WooCommerce 2.4 Compatibility 48 | 49 | = 2015.05.04 - version 1.0.0 = 50 | * Initial Release -------------------------------------------------------------------------------- /screenshots/offline-gateway-checkout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bekarice/woocommerce-gateway-offline/76ff6f1d89302bbe79b037d105085dab4a932e26/screenshots/offline-gateway-checkout.png -------------------------------------------------------------------------------- /screenshots/offline-gateway-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bekarice/woocommerce-gateway-offline/76ff6f1d89302bbe79b037d105085dab4a932e26/screenshots/offline-gateway-settings.png -------------------------------------------------------------------------------- /screenshots/offline-gateway-thankyou.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bekarice/woocommerce-gateway-offline/76ff6f1d89302bbe79b037d105085dab4a932e26/screenshots/offline-gateway-thankyou.png -------------------------------------------------------------------------------- /woocommerce-gateway-offline.php: -------------------------------------------------------------------------------- 1 | ' . __( 'Configure', 'wc-gateway-offline' ) . '' 60 | ); 61 | 62 | return array_merge( $plugin_links, $links ); 63 | } 64 | add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wc_offline_gateway_plugin_links' ); 65 | 66 | 67 | /** 68 | * Offline Payment Gateway 69 | * 70 | * Provides an Offline Payment Gateway; mainly for testing purposes. 71 | * We load it later to ensure WC is loaded first since we're extending it. 72 | * 73 | * @class WC_Gateway_Offline 74 | * @extends WC_Payment_Gateway 75 | * @version 1.0.0 76 | * @package WooCommerce/Classes/Payment 77 | * @author SkyVerge 78 | */ 79 | add_action( 'plugins_loaded', 'wc_offline_gateway_init', 11 ); 80 | 81 | function wc_offline_gateway_init() { 82 | 83 | class WC_Gateway_Offline extends WC_Payment_Gateway { 84 | 85 | /** 86 | * Constructor for the gateway. 87 | */ 88 | public function __construct() { 89 | 90 | $this->id = 'offline_gateway'; 91 | $this->icon = apply_filters('woocommerce_offline_icon', ''); 92 | $this->has_fields = false; 93 | $this->method_title = __( 'Offline', 'wc-gateway-offline' ); 94 | $this->method_description = __( 'Allows offline payments. Very handy if you use your cheque gateway for another payment method, and can help with testing. Orders are marked as "on-hold" when received.', 'wc-gateway-offline' ); 95 | 96 | // Load the settings. 97 | $this->init_form_fields(); 98 | $this->init_settings(); 99 | 100 | // Define user set variables 101 | $this->title = $this->get_option( 'title' ); 102 | $this->description = $this->get_option( 'description' ); 103 | $this->instructions = $this->get_option( 'instructions', $this->description ); 104 | 105 | // Actions 106 | add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); 107 | add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); 108 | 109 | // Customer Emails 110 | add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); 111 | } 112 | 113 | 114 | /** 115 | * Initialize Gateway Settings Form Fields 116 | */ 117 | public function init_form_fields() { 118 | 119 | $this->form_fields = apply_filters( 'wc_offline_form_fields', array( 120 | 121 | 'enabled' => array( 122 | 'title' => __( 'Enable/Disable', 'wc-gateway-offline' ), 123 | 'type' => 'checkbox', 124 | 'label' => __( 'Enable Offline Payment', 'wc-gateway-offline' ), 125 | 'default' => 'yes' 126 | ), 127 | 128 | 'title' => array( 129 | 'title' => __( 'Title', 'wc-gateway-offline' ), 130 | 'type' => 'text', 131 | 'description' => __( 'This controls the title for the payment method the customer sees during checkout.', 'wc-gateway-offline' ), 132 | 'default' => __( 'Offline Payment', 'wc-gateway-offline' ), 133 | 'desc_tip' => true, 134 | ), 135 | 136 | 'description' => array( 137 | 'title' => __( 'Description', 'wc-gateway-offline' ), 138 | 'type' => 'textarea', 139 | 'description' => __( 'Payment method description that the customer will see on your checkout.', 'wc-gateway-offline' ), 140 | 'default' => __( 'Please remit payment to Store Name upon pickup or delivery.', 'wc-gateway-offline' ), 141 | 'desc_tip' => true, 142 | ), 143 | 144 | 'instructions' => array( 145 | 'title' => __( 'Instructions', 'wc-gateway-offline' ), 146 | 'type' => 'textarea', 147 | 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'wc-gateway-offline' ), 148 | 'default' => '', 149 | 'desc_tip' => true, 150 | ), 151 | ) ); 152 | } 153 | 154 | 155 | /** 156 | * Output for the order received page. 157 | */ 158 | public function thankyou_page() { 159 | if ( $this->instructions ) { 160 | echo wpautop( wptexturize( $this->instructions ) ); 161 | } 162 | } 163 | 164 | 165 | /** 166 | * Add content to the WC emails. 167 | * 168 | * @access public 169 | * @param WC_Order $order 170 | * @param bool $sent_to_admin 171 | * @param bool $plain_text 172 | */ 173 | public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { 174 | 175 | if ( $this->instructions && ! $sent_to_admin && $this->id === $order->payment_method && $order->has_status( 'on-hold' ) ) { 176 | echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; 177 | } 178 | } 179 | 180 | 181 | /** 182 | * Process the payment and return the result 183 | * 184 | * @param int $order_id 185 | * @return array 186 | */ 187 | public function process_payment( $order_id ) { 188 | 189 | $order = wc_get_order( $order_id ); 190 | 191 | // Mark as on-hold (we're awaiting the payment) 192 | $order->update_status( 'on-hold', __( 'Awaiting offline payment', 'wc-gateway-offline' ) ); 193 | 194 | // Reduce stock levels 195 | $order->reduce_order_stock(); 196 | 197 | // Remove cart 198 | WC()->cart->empty_cart(); 199 | 200 | // Return thankyou redirect 201 | return array( 202 | 'result' => 'success', 203 | 'redirect' => $this->get_return_url( $order ) 204 | ); 205 | } 206 | 207 | } // end \WC_Gateway_Offline class 208 | } --------------------------------------------------------------------------------