Skip to content

Commit

Permalink
Merge pull request #23 from vanengers/master
Browse files Browse the repository at this point in the history
Fix WooCommerce add_error with wp_add_notice
  • Loading branch information
lvgunst committed Feb 23, 2015
2 parents 4a27d08 + ee1ccb4 commit b02ff12
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
9 changes: 5 additions & 4 deletions MPM/mpm_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,13 @@ public function process_payment($order_id)
{
if (defined('WP_DEBUG') && WP_DEBUG)
{
$woocommerce->add_error(__('Could not create payment.', 'MPM') . ' Reason: invalid order ID');
$mpm->add_notice(__('Could not create payment.', 'MPM') . ' Reason: invalid order ID', 'error');
}
else
{
$woocommerce->add_error(__('Could not create payment.', 'MPM'));
$mpm->add_notice(__('Could not create payment.', 'MPM'), 'error');
}

return array('result' => 'failure');
}

Expand Down Expand Up @@ -266,11 +267,11 @@ public function process_payment($order_id)
{
if (defined('WP_DEBUG') && WP_DEBUG)
{
$woocommerce->add_error(__('Could not create payment.', 'MPM') . ' Reason: ' . $e->getMessage());
$mpm->add_notice(__('Could not create payment.', 'MPM') . ' Reason: ' . $e->getMessage(), 'error');
}
else
{
$woocommerce->add_error(__('Could not create payment.', 'MPM'));
$mpm->add_notice(__('Could not create payment.', 'MPM'), 'error');
}

return array('result' => 'failure');
Expand Down
31 changes: 31 additions & 0 deletions MPM/mpm_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,4 +545,35 @@ public function get_issuers ($method = NULL)
return array();
}
}

/**
* Add a woocommerce notification message
*
* @param string $message Notification message
* @param string $type Notification type, default = notice
*/
public function add_notice ($message, $type = 'notice')
{
global $woocommerce;
$type = in_array($type, array('notice','error','success')) ? $type : 'notice';

// Check for existence of new notification api. Else use previous add_error
if (function_exists('wc_add_notice'))
{
wc_add_notice($message, $type);
}
else
{
// Retrocompatibility WooCommerce < 2.1
switch ($type)
{
case "error" :
$woocommerce->add_error($message);
break;
default :
$woocommerce->add_message($message);
break;
}
}
}
}

0 comments on commit b02ff12

Please sign in to comment.