woocommerce_ppay_Init

The Postepay Gateway per Woocommerce woocommerce ppay Init function.

Description

woocommerce_ppay_Init(); 

Usage

  1. if ( !function_exists( 'woocommerce_ppay_Init' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'postepay-gateway-per-woocommerce/wc-postepay.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = woocommerce_ppay_Init(); 
  7.  

Defined (1)

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

/wc-postepay.php  
  1. function woocommerce_ppay_Init() { 
  2. if (!class_exists('WC_Payment_Gateway')) 
  3. return; 
  4.  
  5. class WC_Gateway_PPAY extends WC_Payment_Gateway { 
  6.  
  7. public function __construct() {  
  8. $this->id = 'ppay'; 
  9. $this->icon = apply_filters('woocommerce_ppay_icon', ''); 
  10. $this->has_fields = false; 
  11. $this->method_title = __( 'PostePay (o ricaricabile)', '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->ppay_number = $this->get_option( 'ppay_number' ); 
  21. $this->ppay_user = $this->get_option( 'ppay_user' ); 
  22.  
  23. // Actions 
  24. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); 
  25. add_action( 'woocommerce_thankyou_ppay', array( $this, 'thankyou_page' ) ); 
  26.  
  27. // Customer Emails 
  28. add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 2 ); 
  29. }  
  30.  
  31. /** 
  32. * Initialise Gateway Settings Form Fields 
  33. */ 
  34. function init_form_fields() { 
  35.  
  36. $this->form_fields = array( 
  37. 'enabled' => array( 
  38. 'title' => __( 'Abilita/Disabilita', 'woocommerce' ),  
  39. 'type' => 'checkbox',  
  40. 'label' => __( 'Abilita Postepay/CartaRicaricabile', 'woocommerce' ),  
  41. 'default' => 'yes' 
  42. ),  
  43. 'title' => array( 
  44. 'title' => __( 'Titolo', 'woocommerce' ),  
  45. 'type' => 'text',  
  46. 'description' => __( 'Definisci il titolo del sistema di pagamento.', 'woocommerce' ),  
  47. 'default' => __( 'Postepay', 'woocommerce' ) 
  48. ),  
  49. 'description' => array( 
  50. 'title' => __( 'Messaggio personalizzato', 'woocommerce' ),  
  51. 'type' => 'textarea',  
  52. 'description' => __( 'Spiega al cliente come procedere con la ricarica Postepay o sistema similare. Segnala che la merce non sar inviata fino al ricevimento della ricarica.', 'woocommerce' ),  
  53. 'default' => __('Paga con una ricarica Postepay. Mandaci una mail appena hai fatto il versamento indicando il numero d\'ordine e provvederemo all\'invio della merce.', 'woocommerce') 
  54. ),  
  55. 'ppay_number' => array( 
  56. 'title' => __( 'Numero Postepay (o ricaricabile)', 'woocommerce' ),  
  57. 'type' => 'text',  
  58. 'description' => '',  
  59. 'default' => '' 
  60. ),  
  61. 'ppay_user' => array( 
  62. 'title' => __( 'Intestatario Postepay ', 'woocommerce' ),  
  63. 'type' => 'text',  
  64. 'description' => '',  
  65. 'default' => '' 
  66. ),  
  67.  
  68. ); 
  69.  
  70. } // End init_form_fields() 
  71.  
  72. /** 
  73. * Admin Panel Options  
  74. * - Options for bits like 'title' and availability on a country-by-country basis 
  75. * @since 1.0.0 
  76. */ 
  77. public function admin_options() { 
  78. ?> 
  79. <h3><?php _e('Postepay (o ricaricabile)', 'woocommerce'); ?></h3> 
  80. <p><?php _e('Permetti pagamenti attraverso Postepay o sistema similare', 'woocommerce'); ?></p> 
  81. <table class="form-table"> 
  82. <?php 
  83. // Generate the HTML For the settings form. 
  84. $this->generate_settings_html(); 
  85. ?> 
  86. </table><!--/.form-table--> 
  87. <?php 
  88. } // End admin_options() 
  89.  
  90.  
  91. /** 
  92. * Output for the order received page. 
  93. **/ 
  94.  
  95.  
  96. function thankyou_page() { 
  97. if ( $description = $this->get_description() ) 
  98. echo wpautop( wptexturize( wp_kses_post( $description ) ) ); 
  99.  
  100. echo '<h2>' . __( 'Informazioni di pagamento', 'woocommerce' ) . '</h2>'; 
  101.  
  102. echo '<ul class="order_details ppay_details">'; 
  103.  
  104. $fields = apply_filters('woocommerce_ppay_fields', array( 
  105. 'ppay_number'=> __('Numero Postepay', 'woocommerce'),  
  106. 'ppay_user'=> __('Intestatario Postepay', 'woocommerce') 
  107. )); 
  108.  
  109. foreach ( $fields as $key=>$value ) { 
  110. if ( ! empty( $this->$key ) ) { 
  111. echo '<li class="' . esc_attr( $key ) . '">' . esc_attr( $value ) . ': <strong>' . wptexturize( $this->$key ) . '</strong></li>'; 
  112.  
  113. echo '</ul>'; 
  114.  
  115. /** 
  116. * Add content to the WC emails. 
  117. **/ 
  118. function email_instructions( $order, $sent_to_admin ) { 
  119.  
  120. if ( $sent_to_admin ) return; 
  121.  
  122. if ( $order->status !== 'on-hold') return; 
  123.  
  124. if ( $order->payment_method !== 'ppay') return; 
  125.  
  126. if ( $description = $this->get_description() ) 
  127. echo wpautop( wptexturize( $description ) ); 
  128.  
  129. ?><h2><?php _e('Informazioni', 'woocommerce') ?></h2><ul class="order_details ppay_details"><?php 
  130.  
  131. $fields = apply_filters('woocommerce_ppay_fields', array( 
  132. 'ppay_number'=> __('Numero Postepay (o ricaricabile)', 'woocommerce'),  
  133. 'ppay_user'=> __('Intestatario Postepay', 'woocommerce') 
  134. )); 
  135.  
  136. foreach ($fields as $key=>$value) : 
  137. if(!empty($this->$key)) : 
  138. echo '<li class="'.$key.'">'.$value.': <strong>'.wptexturize($this->$key).'</strong></li>'; 
  139. endif; 
  140. endforeach; 
  141.  
  142. ?></ul><?php 
  143.  
  144. /** 
  145. * Process the payment and return the result 
  146. **/ 
  147. function process_payment( $order_id ) { 
  148. global $woocommerce; 
  149.  
  150. $order = new WC_Order( $order_id ); 
  151.  
  152. // Mark as on-hold (we're awaiting the payment) 
  153. $order->update_status('on-hold', __('In attesa di conferma ricarica', 'woocommerce')); 
  154.  
  155. // Reduce stock levels 
  156. $order->reduce_order_stock(); 
  157.  
  158. // Remove cart 
  159. $woocommerce->cart->empty_cart(); 
  160.  
  161. // Return thankyou redirect 
  162. return array( 
  163. 'result' => 'success',  
  164. 'redirect' => $this->get_return_url( $order ) 
  165. ); 
  166.  
  167.  
  168. /** 
  169. * Add the Gateway to WooCommerce 
  170. **/ 
  171. function woocommerce_add_ppay_gateway($methods) { 
  172. $methods[] = 'WC_Gateway_PPAY'; 
  173. return $methods; 
  174.  
  175. add_filter('woocommerce_payment_gateways', 'woocommerce_add_ppay_gateway' );