diff --git a/MPM/mpm_gateway.php b/MPM/mpm_gateway.php index 93c0560a6..f0aa69b94 100644 --- a/MPM/mpm_gateway.php +++ b/MPM/mpm_gateway.php @@ -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'); } @@ -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'); diff --git a/MPM/mpm_settings.php b/MPM/mpm_settings.php index d928d3833..9a6809523 100644 --- a/MPM/mpm_settings.php +++ b/MPM/mpm_settings.php @@ -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; + } + } + } }