Skip to content

Commit 073aa35

Browse files
committed
Add commonly used notice functions to SV_WC_Helper
Seems that subs renewals may be affected as these functions are not available in the admin. Possibly related tickets: https://woothemes.zendesk.com/agent/tickets/215778 https://woothemes.zendesk.com/agent/tickets/223219 https://woothemes.zendesk.com/agent/tickets/222842
1 parent 01d4a12 commit 073aa35

File tree

5 files changed

+83
-26
lines changed

5 files changed

+83
-26
lines changed

woocommerce/changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
*** SkyVerge WooCommerce Plugin Framework Changelog ***
22

3+
2014.nn.nn - version 3.0.1-1
4+
* Fix - Add commonly used notice functions to avoid errors when renewing subscriptions
5+
36
2014.10.15 - version 3.0.1
47
* Tweak - Method visibility changed from private to protected to allow adjustment via sub-classes
58
* Fix - Fix "Wrong parameters for Exception" fatal error

woocommerce/class-sv-wc-helper.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,60 @@ public static function get_request( $key ) {
452452
}
453453

454454

455+
/**
456+
* Get the count of notices added, either for all notices (default) or for one
457+
* particular notice type specified by $notice_type.
458+
*
459+
* WC notice funtions are not available in the admin
460+
*
461+
* @since 3.0.1-1
462+
* @param string $notice_type The name of the notice type - either error, success or notice. [optional]
463+
* @return int
464+
*/
465+
public static function wc_notice_count( $notice_type = '' ) {
466+
467+
if ( function_exists( 'wc_notice_count' ) ) {
468+
return wc_notice_count( $notice_type );
469+
}
470+
471+
return 0;
472+
}
473+
474+
475+
/**
476+
* Add and store a notice.
477+
*
478+
* WC notice funtions are not available in the admin
479+
*
480+
* @since 3.0.1-1
481+
* @param string $message The text to display in the notice.
482+
* @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
483+
*/
484+
public static function wc_add_notice( $message, $notice_type = 'success' ) {
485+
486+
if ( function_exists( 'wc_add_notice' ) ) {
487+
wc_add_notice( $message, $notice_type );
488+
}
489+
}
490+
491+
492+
/**
493+
* Print a single notice immediately
494+
*
495+
* WC notice funtions are not available in the admin
496+
*
497+
* @since 3.0.1-1
498+
* @param string $message The text to display in the notice.
499+
* @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
500+
*/
501+
public static function wc_print_notice( $message, $notice_type = 'success' ) {
502+
503+
if ( function_exists( 'wc_print_notice' ) ) {
504+
wc_print_notice( $message, $notice_type );
505+
}
506+
}
507+
508+
455509
}
456510

457511
endif; // Class exists check

woocommerce/class-sv-wc-plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@
8484
* Use the standard WordPress/WooCommerce `is_*` methods when adding the notice
8585
* to control which pages it does (or does not) display on.
8686
*
87-
* @version 3.0.1
87+
* @version 3.0.1-1
8888
*/
8989
abstract class SV_WC_Plugin {
9090

9191
/** Plugin Framework Version */
92-
const VERSION = '3.0.1';
92+
const VERSION = '3.0.1-1';
9393

9494
/** @var string plugin id */
9595
private $id;

woocommerce/payment-gateway/class-sv-wc-payment-gateway-direct.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function validate_fields() {
111111

112112
// unknown token?
113113
if ( ! $this->has_payment_token( get_current_user_id(), SV_WC_Helper::get_post( 'wc-' . $this->get_id_dasherized() . '-payment-token' ) ) ) {
114-
wc_add_notice( _x( 'Payment error, please try another payment method or contact us to complete your transaction.', 'Supports tokenization', $this->text_domain ), 'error' );
114+
SV_WC_Helper::wc_add_notice( _x( 'Payment error, please try another payment method or contact us to complete your transaction.', 'Supports tokenization', $this->text_domain ), 'error' );
115115
$is_valid = false;
116116
}
117117

@@ -184,7 +184,7 @@ protected function validate_credit_card_expiration_date( $expiration_month, $exp
184184
( $expiration_year == $current_year && $expiration_month < $current_month ) ||
185185
$expiration_year > $current_year + 20
186186
) {
187-
wc_add_notice( _x( 'Card expiration date is invalid', 'Supports direct credit card', $this->text_domain ), 'error' );
187+
SV_WC_Helper::wc_add_notice( _x( 'Card expiration date is invalid', 'Supports direct credit card', $this->text_domain ), 'error' );
188188
$is_valid = false;
189189
}
190190

@@ -208,23 +208,23 @@ protected function validate_credit_card_account_number( $account_number ) {
208208

209209
if ( empty( $account_number ) ) {
210210

211-
wc_add_notice( _x( 'Card number is missing', 'Supports direct credit card', $this->text_domain ), 'error' );
211+
SV_WC_Helper::wc_add_notice( _x( 'Card number is missing', 'Supports direct credit card', $this->text_domain ), 'error' );
212212
$is_valid = false;
213213

214214
} else {
215215

216216
if ( strlen( $account_number ) < 12 || strlen( $account_number ) > 19 ) {
217-
wc_add_notice( _x( 'Card number is invalid (wrong length)', 'Supports direct credit card', $this->text_domain ), 'error' );
217+
SV_WC_Helper::wc_add_notice( _x( 'Card number is invalid (wrong length)', 'Supports direct credit card', $this->text_domain ), 'error' );
218218
$is_valid = false;
219219
}
220220

221221
if ( ! ctype_digit( $account_number ) ) {
222-
wc_add_notice( _x( 'Card number is invalid (only digits allowed)', 'Supports direct credit card', $this->text_domain ), 'error' );
222+
SV_WC_Helper::wc_add_notice( _x( 'Card number is invalid (only digits allowed)', 'Supports direct credit card', $this->text_domain ), 'error' );
223223
$is_valid = false;
224224
}
225225

226226
if ( ! SV_WC_Payment_Gateway_Helper::luhn_check( $account_number ) ) {
227-
wc_add_notice( _x( 'Card number is invalid', 'Supports direct credit card', $this->text_domain ), 'error' );
227+
SV_WC_Helper::wc_add_notice( _x( 'Card number is invalid', 'Supports direct credit card', $this->text_domain ), 'error' );
228228
$is_valid = false;
229229
}
230230

@@ -249,20 +249,20 @@ protected function validate_csc( $csc ) {
249249
// validate security code
250250
if ( empty( $csc ) ) {
251251

252-
wc_add_notice( _x( 'Card security code is missing', 'Supports direct credit card', $this->text_domain ), 'error' );
252+
SV_WC_Helper::wc_add_notice( _x( 'Card security code is missing', 'Supports direct credit card', $this->text_domain ), 'error' );
253253
$is_valid = false;
254254

255255
} else {
256256

257257
// digit validation
258258
if ( ! ctype_digit( $csc ) ) {
259-
wc_add_notice( _x( 'Card security code is invalid (only digits are allowed)', 'Supports direct credit card', $this->text_domain ), 'error' );
259+
SV_WC_Helper::wc_add_notice( _x( 'Card security code is invalid (only digits are allowed)', 'Supports direct credit card', $this->text_domain ), 'error' );
260260
$is_valid = false;
261261
}
262262

263263
// length validation
264264
if ( strlen( $csc ) < 3 || strlen( $csc ) > 4 ) {
265-
wc_add_notice( _x( 'Card security code is invalid (must be 3 or 4 digits)', 'Supports direct credit card', $this->text_domain ), 'error' );
265+
SV_WC_Helper::wc_add_notice( _x( 'Card security code is invalid (must be 3 or 4 digits)', 'Supports direct credit card', $this->text_domain ), 'error' );
266266
$is_valid = false;
267267
}
268268

@@ -291,20 +291,20 @@ protected function validate_check_fields( $is_valid ) {
291291
// routing number exists?
292292
if ( empty( $routing_number ) ) {
293293

294-
wc_add_notice( _x( 'Routing Number is missing', 'Supports direct cheque', $this->text_domain ), 'error' );
294+
SV_WC_Helper::wc_add_notice( _x( 'Routing Number is missing', 'Supports direct cheque', $this->text_domain ), 'error' );
295295
$is_valid = false;
296296

297297
} else {
298298

299299
// routing number digit validation
300300
if ( ! ctype_digit( $routing_number ) ) {
301-
wc_add_notice( _x( 'Routing Number is invalid (only digits are allowed)', 'Supports direct cheque', $this->text_domain ), 'error' );
301+
SV_WC_Helper::wc_add_notice( _x( 'Routing Number is invalid (only digits are allowed)', 'Supports direct cheque', $this->text_domain ), 'error' );
302302
$is_valid = false;
303303
}
304304

305305
// routing number length validation
306306
if ( 9 != strlen( $routing_number ) ) {
307-
wc_add_notice( _x( 'Routing number is invalid (must be 9 digits)', 'Supports direct cheque', $this->text_domain ), 'error' );
307+
SV_WC_Helper::wc_add_notice( _x( 'Routing number is invalid (must be 9 digits)', 'Supports direct cheque', $this->text_domain ), 'error' );
308308
$is_valid = false;
309309
}
310310

@@ -313,33 +313,33 @@ protected function validate_check_fields( $is_valid ) {
313313
// account number exists?
314314
if ( empty( $account_number ) ) {
315315

316-
wc_add_notice( _x( 'Account Number is missing', 'Supports direct cheque', $this->text_domain ), 'error' );
316+
SV_WC_Helper::wc_add_notice( _x( 'Account Number is missing', 'Supports direct cheque', $this->text_domain ), 'error' );
317317
$is_valid = false;
318318

319319
} else {
320320

321321
// account number digit validation
322322
if ( ! ctype_digit( $account_number ) ) {
323-
wc_add_notice( _x( 'Account Number is invalid (only digits are allowed)', 'Supports direct cheque', $this->text_domain ), 'error' );
323+
SV_WC_Helper::wc_add_notice( _x( 'Account Number is invalid (only digits are allowed)', 'Supports direct cheque', $this->text_domain ), 'error' );
324324
$is_valid = false;
325325
}
326326

327327
// account number length validation
328328
if ( strlen( $account_number ) < 5 || strlen( $account_number ) > 17 ) {
329-
wc_add_notice( _x( 'Account number is invalid (must be between 5 and 17 digits)', 'Supports direct cheque', $this->text_domain ), 'error' );
329+
SV_WC_Helper::wc_add_notice( _x( 'Account number is invalid (must be between 5 and 17 digits)', 'Supports direct cheque', $this->text_domain ), 'error' );
330330
$is_valid = false;
331331
}
332332
}
333333

334334
// optional drivers license number validation
335335
if ( ! empty( $drivers_license_number ) && preg_match( '/^[a-zA-Z0-9 -]+$/', $drivers_license_number ) ) {
336-
wc_add_notice( _x( 'Drivers license number is invalid', 'Supports direct cheque', $this->text_domain ), 'error' );
336+
SV_WC_Helper::wc_add_notice( _x( 'Drivers license number is invalid', 'Supports direct cheque', $this->text_domain ), 'error' );
337337
$is_valid = false;
338338
}
339339

340340
// optional check number validation
341341
if ( ! empty( $check_number ) && ! ctype_digit( $check_number ) ) {
342-
wc_add_notice( _x( 'Check Number is invalid (only digits are allowed)', 'Supports direct cheque', $this->text_domain ), 'error' );
342+
SV_WC_Helper::wc_add_notice( _x( 'Check Number is invalid (only digits are allowed)', 'Supports direct cheque', $this->text_domain ), 'error' );
343343
$is_valid = false;
344344
}
345345

@@ -2162,7 +2162,7 @@ public function handle_my_payment_methods_actions() {
21622162
// security check
21632163
if ( false === wp_verify_nonce( $_GET['_wpnonce'], 'wc-' . $this->get_id_dasherized() . '-token-action' ) ) {
21642164

2165-
wc_add_notice( _x( 'There was an error with your request, please try again.', 'Supports direct payment method tokenization', $this->text_domain ), 'error' );
2165+
SV_WC_Helper::wc_add_notice( _x( 'There was an error with your request, please try again.', 'Supports direct payment method tokenization', $this->text_domain ), 'error' );
21662166

21672167
wp_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) );
21682168
exit;
@@ -2177,10 +2177,10 @@ public function handle_my_payment_methods_actions() {
21772177

21782178
if ( ! $this->remove_payment_token( $user_id, $token ) ) {
21792179

2180-
wc_add_notice( _x( 'Error removing payment method', 'Supports direct payment method tokenization', $this->text_domain ), 'error' );
2180+
SV_WC_Helper::wc_add_notice( _x( 'Error removing payment method', 'Supports direct payment method tokenization', $this->text_domain ), 'error' );
21812181

21822182
} else {
2183-
wc_add_notice( _x( 'Payment method deleted.', 'Supports direct payment method tokenization', $this->text_domain ) );
2183+
SV_WC_Helper::wc_add_notice( _x( 'Payment method deleted.', 'Supports direct payment method tokenization', $this->text_domain ) );
21842184
}
21852185

21862186
}

woocommerce/payment-gateway/class-sv-wc-payment-gateway.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ protected function mark_order_as_held( $order, $message, $response = null ) {
11851185
if ( ! $user_message ) {
11861186
$user_message = __( 'Your order has been received and is being reviewed. Thank you for your business.', $this->text_domain );
11871187
}
1188-
wc_add_notice( $user_message );
1188+
SV_WC_Helper::wc_add_notice( $user_message );
11891189
}
11901190

11911191

@@ -1218,7 +1218,7 @@ protected function mark_order_as_failed( $order, $error_message, $response = nul
12181218
if ( ! $user_message ) {
12191219
$user_message = __( 'An error occurred, please try again or try an alternate form of payment.', $this->text_domain );
12201220
}
1221-
wc_add_notice( $user_message, 'error' );
1221+
SV_WC_Helper::wc_add_notice( $user_message, 'error' );
12221222
}
12231223

12241224

@@ -1732,12 +1732,12 @@ protected function add_debug_message( $message, $type = 'message' ) {
17321732

17331733
if ( 'message' === $type ) {
17341734

1735-
wc_add_notice( str_replace( "\n", "<br/>", htmlspecialchars( $message ) ), 'notice' );
1735+
SV_WC_Helper::wc_add_notice( str_replace( "\n", "<br/>", htmlspecialchars( $message ) ), 'notice' );
17361736

17371737
} else {
17381738

17391739
// defaults to error message
1740-
wc_add_notice( str_replace( "\n", "<br/>", htmlspecialchars( $message ) ), 'error' );
1740+
SV_WC_Helper::wc_add_notice( str_replace( "\n", "<br/>", htmlspecialchars( $message ) ), 'error' );
17411741
}
17421742
}
17431743

0 commit comments

Comments
 (0)