Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.11 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: Оплата по счету для Woocommerce
  4. * Plugin URI: -
  5. * Description: Данный плагин предоставляет дополнительный способ олпаты предназначенный для юр. лиц.
  6. * Author: -
  7. * Author URI: -
  8. * Version: 0.0.1
  9. * Text Domain: wc-gateway-offline
  10. * Domain Path: /i18n/languages/
  11. *
  12. * Copyright: (c) 2015-2016 SkyVerge, Inc. (info@skyverge.com) and WooCommerce
  13. *
  14. * License: GNU General Public License v3.0
  15. * License URI: http://www.gnu.org/licenses/gpl-3.0.html
  16. *
  17. * @package WC-Gateway-Offline
  18. * @author SkyVerge
  19. * @category Admin
  20. * @copyright Copyright (c) 2015-2016, SkyVerge, Inc. and WooCommerce
  21. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
  22. *
  23. * This offline gateway forks the WooCommerce core "Cheque" payment gateway to create another offline payment method.
  24. */
  25.  
  26. defined( 'ABSPATH' ) or exit;
  27.  
  28.  
  29. // Make sure WooCommerce is active
  30. if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
  31. return;
  32. }
  33.  
  34.  
  35. /**
  36. * Add the gateway to WC Available Gateways
  37. *
  38. * @since 1.0.0
  39. * @param array $gateways all available WC gateways
  40. * @return array $gateways all WC gateways + offline gateway
  41. */
  42. function wc_offline_add_to_gateways( $gateways ) {
  43. $gateways[] = 'WC_Gateway_Offline';
  44. return $gateways;
  45. }
  46. add_filter( 'woocommerce_payment_gateways', 'wc_offline_add_to_gateways' );
  47.  
  48.  
  49. /**
  50. * Adds plugin page links
  51. *
  52. * @since 1.0.0
  53. * @param array $links all plugin links
  54. * @return array $links all plugin links + our custom links (i.e., "Settings")
  55. */
  56. function wc_offline_gateway_plugin_links( $links ) {
  57.  
  58. $plugin_links = array(
  59. '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout&section=offline_gateway' ) . '">' . __( 'Configure', 'wc-gateway-offline' ) . '</a>'
  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. $this->plugin_url = trailingslashit(WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)));
  90.  
  91. $this->id = 'payment-on-account';
  92. $this->icon = apply_filters('woocommerce_offline_icon', '');
  93. $this->has_fields = false;
  94. $this->method_title = __( 'Offline', 'wc-gateway-offline' );
  95. $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' );
  96.  
  97. // Load the settings.
  98. $this->init_form_fields();
  99. $this->init_settings();
  100.  
  101. // Define user set variables
  102. $this->title = $this->get_option( 'title' );
  103. $this->description = $this->get_option( 'description' );
  104. $this->instructions = $this->get_option( 'instructions', $this->description );
  105.  
  106. // Actions
  107. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
  108. add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) );
  109.  
  110. // Customer Emails
  111. add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
  112.  
  113. add_action('wp_print_scripts', array(&$this, 'include_scripts'));
  114. }
  115.  
  116. function include_scripts() {
  117. wp_enqueue_script( 'pa-shape-change', $this->plugin_url . '/js/shape-change.js');
  118. }
  119.  
  120. /**
  121. * Initialize Gateway Settings Form Fields
  122. */
  123.  
  124. public function init_form_fields() {
  125.  
  126. $this->form_fields = apply_filters( 'wc_offline_form_fields', array(
  127.  
  128. 'enabled' => array(
  129. 'title' => __( 'Enable/Disable', 'wc-gateway-offline' ),
  130. 'type' => 'checkbox',
  131. 'label' => __( 'Enable Offline Payment', 'wc-gateway-offline' ),
  132. 'default' => 'yes'
  133. ),
  134.  
  135. 'title' => array(
  136. 'title' => __( 'Title', 'wc-gateway-offline' ),
  137. 'type' => 'text',
  138. 'description' => __( 'This controls the title for the payment method the customer sees during checkout.', 'wc-gateway-offline' ),
  139. 'default' => __( 'Оплата по счету', 'wc-gateway-offline' ),
  140. 'desc_tip' => true,
  141. ),
  142.  
  143. 'description' => array(
  144. 'title' => __( 'Description', 'wc-gateway-offline' ),
  145. 'type' => 'textarea',
  146. 'description' => __( 'Payment method description that the customer will see on your checkout.', 'wc-gateway-offline' ),
  147. 'default' => __( 'Пожалуйста, отправьте платеж на имя магазина при получении или доставке.', 'wc-gateway-offline' ),
  148. 'desc_tip' => true,
  149. ),
  150.  
  151. 'instructions' => array(
  152. 'title' => __( 'Instructions', 'wc-gateway-offline' ),
  153. 'type' => 'textarea',
  154. 'description' => __( 'Инструкции, которые будут добавлены на страницу благодарности и электронные письма.', 'wc-gateway-offline' ),
  155. 'default' => '',
  156. 'desc_tip' => true,
  157. ),
  158. ) );
  159.  
  160. }
  161.  
  162.  
  163. /**
  164. * Output for the order received page.
  165. */
  166. public function thankyou_page() {
  167. if ( $this->instructions ) {
  168. echo wpautop( wptexturize( $this->instructions ) );
  169. echo 'test: bla bla';
  170. }
  171. }
  172.  
  173.  
  174. /**
  175. * Add content to the WC emails.
  176. *
  177. * @access public
  178. * @param WC_Order $order
  179. * @param bool $sent_to_admin
  180. * @param bool $plain_text
  181. */
  182. public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
  183.  
  184. if ( $this->instructions && ! $sent_to_admin && $this->id === $order->payment_method && $order->has_status( 'on-hold' ) ) {
  185. echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
  186. }
  187. }
  188.  
  189.  
  190. /**
  191. * Process the payment and return the result
  192. *
  193. * @param int $order_id
  194. * @return array
  195. */
  196. public function process_payment( $order_id ) {
  197.  
  198. $order = wc_get_order( $order_id );
  199.  
  200. // Mark as on-hold (we're awaiting the payment)
  201. $order->update_status( 'on-hold', __( 'Awaiting offline payment', 'wc-gateway-offline' ) );
  202.  
  203. // Reduce stock levels
  204. $order->reduce_order_stock();
  205.  
  206. // Remove cart
  207. WC()->cart->empty_cart();
  208.  
  209. // Return thankyou redirect
  210. return array(
  211. 'result' => 'success',
  212. 'redirect' => $this->get_return_url( $order )
  213. );
  214. }
  215.  
  216. } // end WC_Gateway_Offline class
  217. }
  218.  
  219. window.onload = function() {
  220. console.log($().jquery);
  221. var formContent = $('#customer_details').html();
  222. var formDefault = true;
  223. $(document).ajaxComplete(function(header) {
  224. $('input').on('click', function() {
  225. console.log($(this).get(0).id);
  226. if($(this).get(0).id == 'payment_method_payment-on-account') {
  227. $('#customer_details').children('div').remove();
  228. formDefault = false;
  229. $('#customer_details').append("<div class='woocommerce-billing-fields'><div class='woocommerce-billing-fields__field-wrapper'><p class='form-row form-row-first validate-required' id='billing_first_name_field' data-priority='10'><label for='billing_first_name' class=''>Имя&nbsp;<abbr class='required' title='обязательно'>*</abbr></label><span class='woocommerce-input-wrapper'><input type='text' class='input-text ' name='name-ep' id='billing_first_name' placeholder='Полное наименование организации или ИП' autocomplete='given-name'></span></p><p class='form-row form-row-wide validate-required validate-phone' id='billing_phone_field' data-priority='100'><label for='billing_phone' class=''>Телефон&nbsp;<abbr class='required' title='обязательно'>*</abbr></label><span class='woocommerce-input-wrapper'><input type='tel' class='input-text ' name='enn' id='billing_phone' placeholder='ИНН' autocomplete='tel'></span></p><p class='form-row form-row-wide validate-required validate-email' id='billing_email_field' data-priority='110'><label for='billing_email' class=''>Email&nbsp;<abbr class='required' title='обязательно'>*</abbr></label><span class='woocommerce-input-wrapper'><input type='email' class='input-text ' name='kpp' id='billing_email' placeholder='КПП' autocomplete='email username'></span></p><p class='form-row form-row-wide validate-required validate-email' id='billing_email_field' data-priority='110'><label for='billing_email' class=''>Email&nbsp;<abbr class='required' title='обязательно'>*</abbr></label><span class='woocommerce-input-wrapper'><input type='email' class='input-text ' name='legal-address' id='billing_email' placeholder='Юридический адрес' autocomplete='email username'></span></p><p class='form-row form-row-wide validate-required validate-email' id='billing_email_field' data-priority='110'><label for='billing_email' class=''>Email&nbsp;<abbr class='required' title='обязательно'>*</abbr></label><span class='woocommerce-input-wrapper'><input type='email' class='input-text ' name='contact-number' id='billing_email' placeholder='Контактный телефон' autocomplete='email username'></span></p><p class='form-row form-row-wide validate-required validate-email' id='billing_email_field' data-priority='110'><label for='billing_email' class=''>Email&nbsp;<abbr class='required' title='обязательно'>*</abbr></label><span class='woocommerce-input-wrapper'><input type='email' class='input-text ' name='email' id='billing_email' placeholder='Электронная почта' autocomplete='email username'></span></p></div></div>");
  230. }
  231. else {
  232. if(formDefault != true) {
  233. $('#customer_details').children('div').remove();
  234. $('#customer_details').append(formContent);
  235. }
  236. formDefault = true;
  237. }
  238. });
  239. });
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement