forked from rendom/bp-woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbp_payment_wc.php
174 lines (134 loc) · 6.68 KB
/
bp_payment_wc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/*
Plugin Name: Postgiro/Bankgiro Payment gateway
Plugin URI: http://wordpress.org/extend/plugins/postgiorbankgiro-payment-method-for-woocoommerce
Description: Woocommerce payment gateway: Postgiro / Bankgiro (Swedish)
Author: developer-blog
Author URI: http://developer-blog.com
Version: 1.0.3
*/
/**
* @package bc_payment_wc
* @version 1.0.3
*/
add_action('plugins_loaded', 'init_bp_payment', 0);
function init_bp_payment() {
if ( ! class_exists( 'WC_Payment_Gateway' ) ) { return; }
class bp_payment_wc extends WC_Payment_Gateway{
function __construct() {
$this->id = "bankgiro-postgiro";
$this->icon = "";
$this->has_fields = false;
$this->init_form_fields();
$this->init_settings();
$this->title = $this->settings['title'];
$this->description = $this->settings['description'];
$this->bankgironr = $this->settings['bankgironr'];
$this->postgironr = $this->settings['postgironr'];
if ( is_admin() ) {
add_action( 'woocommerce_update_options_payment_gateways', array( $this, 'process_admin_options' ) ); // WC < 2.0
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); // WC >= 2.0
}
//add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
add_action('woocommerce_thankyou_bankgiro-postgiro', array(&$this, 'thankyou_page'));
add_action('woocommerce_email_before_order_table', array(&$this, 'email_instructions'), 10, 2);
}
function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woothemes' ),
'type' => 'checkbox',
'label' => __('Aktivera postgiro/bankgiro som betalningsmetod', 'woothemes' ),
'default' => 'yes'
),
'title' => array(
'title' => __( 'Title', 'woothemes' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'woothemes' ),
'default' => __( 'Bankgiro/Postgiro', 'woothemes' )
),
'description' => array(
'title' => __( 'Customer Message', 'woothemes' ),
'type' => 'textarea',
'default' => 'Gör din betalning direkt till vårt bankgiro/postgiro. Använd order-ID som betalningsreferens. Din order levereras när vi mottagit din betalning.',
'description' => 'Ge kunden instruktioner hur man betalar via bankgiro/postgiro och låt kunden veta att ordern inte levereras innan betalningen mottagits.'
),
'bankgironr' => array(
'title' => __( 'Bankgironummer', 'woothemes' ),
'type' => 'text',
'description' => __( 'Ditt bankgiornummer (Lämna tomt om du enbart vill använda postgiro)', 'woothemes' ),
'default' => ''
),
'postgironr' => array(
'title' => __( 'Postgironummer', 'woothemes' ),
'type' => 'text',
'description' => __( 'Ditt postgironummer (Lämna tomt om du enbart vill använda bankgiro)', 'woothemes' ),
'default' => ''
)
);
}
public function admin_options() {
?>
<h3><?php _e('Bankgiro/Postgiro betalning', 'woothemes'); ?></h3>
<table class="form-table">
<?php
$this->generate_settings_html();
?>
</table>
<?php
}
function payment_fields() {
if ($this->description) echo wpautop(wptexturize($this->description));
}
function thankyou_page() {
if ($this->description) echo wpautop(wptexturize($this->description));
?><h2><?php _e('Betalning', 'woothemes') ?></h2><ul class="order_details bankgiro-postgiro_details"><?php
$fields = array(
'bankgironr' => __('Bankgironummer', 'woothemes'),
'postgironr'=> __('Postgironummern', 'woothemes'),
);
foreach ($fields as $key=>$value) :
if(!empty($this->$key)) :
echo '<li class="'.$key.'">'.$value.': <strong>'.wptexturize($this->$key).'</strong></li>';
endif;
endforeach;
?></ul><?php
}
function email_instructions( $order, $sent_to_admin ) {
if ( $sent_to_admin ) return;
if ( $order->status !== 'on-hold') return;
if ( $order->payment_method !== 'bankgiro-postgiro') return;
if ($this->description) echo wpautop(wptexturize($this->description));
?><h2><?php _e('Betalning', 'woothemes') ?></h2><ul class="order_details bankgiro-postgiro_details"><?php
$fields = array(
'bankgironr' => __('Bankgironummer', 'woothemes'),
'postgironr'=> __('Postgironummern', 'woothemes'),
);
foreach ($fields as $key=>$value) :
if(!empty($this->$key)) :
echo '<li class="'.$key.'">'.$value.': <strong>'.wptexturize($this->$key).'</strong></li>';
endif;
endforeach;
?></ul><?php
}
function process_payment( $order_id ) {
global $woocommerce;
$order = new WC_Order($order_id);
// Mark as on-hold (we're awaiting the cheque)
$order->update_status('on-hold', __('Inväntar betalning', 'woothemes'));
// Reduce stock levels
$order->reduce_order_stock();
// Remove cart
$woocommerce->cart->empty_cart();
// Return thankyou redirect
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
}
}
function add_bp_gateway( $methods ) {
$methods[] = 'bp_payment_wc'; return $methods;
}
add_filter('woocommerce_payment_gateways', 'add_bp_gateway' );
}