function wpuw_redirect_to_checkout()
{
    if (isset($_POST['wpuw_add_product'])) {
        $product_id = (int) apply_filters('woocommerce_add_to_cart_product_id', $_POST['add-to-cart']);
        if (has_term('credit', 'product_cat', $product_id)) {
            global $woocommerce;
            wc_clear_notices();
            return $woocommerce->cart->get_checkout_url();
        }
    }
}
 /**
  * Frontend Shortcode Handler
  *
  * @param array $atts array of attributes
  * @param string $content text within enclosing form of shortcode element
  * @param string $shortcodename the shortcode found, when == callback name
  * @return string $output returns the modified html string
  */
 function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
 {
     $output = "";
     $meta['el_class'];
     global $woocommerce, $product;
     if (!is_object($woocommerce) || !is_object($woocommerce->query) || empty($product)) {
         return;
     }
     // $product = wc_get_product();
     $output .= "<div class='av-woo-purchase-button " . $meta['el_class'] . "'>";
     ob_start();
     wc_clear_notices();
     woocommerce_template_single_add_to_cart();
     $output .= ob_get_clean();
     $output .= "</div>";
     return $output;
 }
 public function maybe_apply_subscriber_discount()
 {
     $user_id = get_current_user_id();
     if ($user_id) {
         $discount_coupon_code = MP_Integration::$discount_coupon_code;
         if (!empty($discount_coupon_code)) {
             $sub_id = get_user_meta($user_id, 'mp_subscription_id', true);
             if ($sub_id) {
                 if (!WC()->cart->has_discount($discount_coupon_code)) {
                     WC()->cart->add_discount($discount_coupon_code);
                 }
                 wc_clear_notices();
             } else {
                 WC()->cart->remove_coupon($discount_coupon_code);
             }
         }
     }
 }
 /**
  * Frontend Shortcode Handler
  *
  * @param array $atts array of attributes
  * @param string $content text within enclosing form of shortcode element
  * @param string $shortcodename the shortcode found, when == callback name
  * @return string $output returns the modified html string
  */
 function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
 {
     $output = "";
     $meta['el_class'];
     global $woocommerce, $product;
     if (!is_object($woocommerce) || !is_object($woocommerce->query) || empty($product)) {
         return;
     }
     $temp = $product->post->post_content;
     $product->post->post_content = "";
     // $product = wc_get_product();
     $output .= "<div class='av-woo-product-review av-woo-product-tabs product " . $meta['el_class'] . "'>";
     ob_start();
     wc_clear_notices();
     woocommerce_output_product_data_tabs();
     // comments_template('reviews');
     $output .= ob_get_clean();
     $output .= "</div>";
     $product->post->post_content = $temp;
     return $output;
 }
/**
 * Prints messages and errors which are stored in the session, then clears them.
 *
 * @since 2.1
 */
function wc_print_notices()
{
    $all_notices = WC()->session->get('wc_notices', array());
    $notice_types = apply_filters('woocommerce_notice_types', array('error', 'success', 'notice'));
    foreach ($notice_types as $notice_type) {
        if (wc_notice_count($notice_type) > 0) {
            wc_get_template("notices/{$notice_type}.php", array('messages' => $all_notices[$notice_type]));
        }
    }
    wc_clear_notices();
}
 public function cart_view()
 {
     if ($this->isSilenced()) {
         $this->getApplicationContext()->getComponent('\\FS\\Components\\Options')->log($this->notifications);
     } else {
         \wc_clear_notices();
         foreach ($this->notifications as $type => $notifications) {
             if (!$notifications) {
                 continue;
             }
             $html = implode('<br/>', $notifications);
             \wc_add_notice($html, $type);
         }
     }
     if ($this->prev) {
         return $this->restore();
     }
     $this->scope();
     return $this->cleanup();
 }
 /**
  *  PayPal Express Checkout
  *
  *  Main action function that handles PPE actions:
  *  1. 'expresscheckout' - Initiates the Express Checkout process; called by the checkout button.
  *  2. 'revieworder' - Customer has reviewed the order. Saves shipping info to order.
  *  3. 'payaction' - Customer has pressed "Place Order" on the review page.
  */
 function paypal_express_checkout($posted = null)
 {
     if (!empty($posted) || isset($_GET['pp_action']) && $_GET['pp_action'] == 'expresscheckout') {
         if (sizeof(WC()->cart->get_cart()) > 0) {
             // The customer has initiated the Express Checkout process with the button on the cart page
             if (!defined('WOOCOMMERCE_CHECKOUT')) {
                 define('WOOCOMMERCE_CHECKOUT', true);
             }
             $this->add_log('Start Express Checkout');
             /**
              * Check if the EC button used was the PayPal Credit button.
              * This $usePayPalCredit flag will be used to adjust the SEC request accordingly.
              */
             if (isset($_GET['use_paypal_credit']) && 'true' == $_GET['use_paypal_credit']) {
                 $usePayPalCredit = true;
             } else {
                 $usePayPalCredit = false;
             }
             WC()->cart->calculate_totals();
             $order_id = WC()->checkout()->create_order();
             $order = new WC_Order($order_id);
             if (isset($_SESSION['line_item'])) {
                 unset($_SESSION['line_item']);
             }
             $lineitems_prepare = $this->prepare_line_items($order);
             $lineitems = $_SESSION['line_item'];
             //$paymentAmount    = WC()->cart->get_total();
             $order_obj = $order->get_order_item_totals();
             $current_currency = get_woocommerce_currency_symbol(get_woocommerce_currency());
             $paymentAmount_amt = strip_tags($order_obj['order_total']['value']);
             $payment_exp_ary = explode(';', $paymentAmount_amt);
             $paymentAmount_amt_final_ec = str_replace($current_currency, '', $paymentAmount_amt);
             $paymentAmount_amt_final = str_replace(',', '', $paymentAmount_amt_final_ec);
             $paymentAmount = round($paymentAmount_amt_final, 2);
             if (isset($order->order_shipping_tax) && !empty($order->order_shipping_tax)) {
                 update_post_meta($order_id, 'shipping_taxamt_own', $order->order_shipping_tax);
             }
             $order->get_items();
             //Check if review order page is exist, otherwise re-create it on the fly
             $review_order_page_url = get_permalink(wc_get_page_id('review_order'));
             if (!$review_order_page_url) {
                 $this->add_log(__('Review Order Page not found, re-create it. ', 'paypal-for-woocommerce'));
                 include_once WC()->plugin_path() . '/includes/admin/wc-admin-functions.php';
                 $page_id = wc_create_page(esc_sql(_x('review-order', 'page_slug', 'woocommerce')), 'woocommerce_review_order_page_id', __('Checkout &rarr; Review Order', 'paypal-for-woocommerce'), '[woocommerce_review_order]', wc_get_page_id('checkout'));
                 $review_order_page_url = get_permalink($page_id);
             }
             $returnURL = urlencode(add_query_arg('pp_action', 'revieworder', $review_order_page_url));
             $cancelURL = isset($this->settings['cancel_page']) ? get_the_permalink($this->settings['cancel_page']) : WC()->cart->get_cart_url();
             $cancelURL = apply_filters('angelleye_express_cancel_url', urlencode($cancelURL));
             $resArray = $this->CallSetExpressCheckout($paymentAmount, $returnURL, $cancelURL, $usePayPalCredit, $posted, $lineitems, $order);
             $ack = strtoupper($resArray["ACK"]);
             /**
              * I've replaced the original redirect URL's here with
              * what the PayPal class library returns so that options like
              * "skip details" will work correctly with PayPal's review pages.
              */
             if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
                 $this->add_log('Redirecting to PayPal');
                 if (isset($_SESSION['line_item'])) {
                     unset($_SESSION['line_item']);
                 }
                 if (isset($_POST['terms']) && $_POST['terms'] == 'on') {
                     update_post_meta($order->id, 'paypal_for_woocommerce_terms_on', 'yes');
                 }
                 if (isset($_POST['billing_address_1']) && !empty($_POST['billing_address_1']) && empty($_POST['createaccount'])) {
                     update_post_meta($order->id, 'paypal_for_woocommerce_create_act', 'yes');
                 }
                 $boolvar = is_cart();
                 if (is_ajax()) {
                     $result = array('redirect' => $resArray['REDIRECTURL'], 'result' => 'success');
                     is_product();
                     echo json_encode($result);
                     exit;
                 } else {
                     //$this->RedirectToPayPal( $resArray["TOKEN"] );
                     wp_redirect($resArray['REDIRECTURL']);
                     exit;
                 }
             } else {
                 // Display a user friendly Error on the page and log details
                 $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
                 $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
                 $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
                 $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
                 $this->add_log(__('SetExpressCheckout API call failed. ', 'paypal-for-woocommerce'));
                 $this->add_log(__('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg);
                 $this->add_log(__('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg);
                 $this->add_log(__('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode);
                 $this->add_log(__('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode);
                 // Notice admin if has any issue from PayPal
                 $message = '';
                 if ($this->error_email_notify) {
                     $admin_email = get_option("admin_email");
                     $message .= __("SetExpressCheckout API call failed.", "paypal-for-woocommerce") . "\n\n";
                     $message .= __('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode . "\n";
                     $message .= __('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode . "\n";
                     $message .= __('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg . "\n";
                     $message .= __('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg . "\n";
                     $error_email_notify_mes = apply_filters('angelleye_ec_error_email_notify_message', $message, $ErrorCode, $ErrorSeverityCode, $ErrorShortMsg, $ErrorLongMsg);
                     $subject = "PayPal Express Checkout Error Notification";
                     $error_email_notify_subject = apply_filters('angelleye_ec_error_email_notify_subject', $subject);
                     wp_mail($admin_email, $error_email_notify_subject, $error_email_notify_mes);
                 }
                 // Generate error message based on Error Display Type setting
                 if ($this->error_display_type == 'detailed') {
                     $sec_error_notice = $ErrorCode . ' - ' . $ErrorLongMsg;
                     $error_display_type_message = sprintf(__($sec_error_notice, 'paypal-for-woocommerce'));
                 } else {
                     $error_display_type_message = sprintf(__('There was a problem paying with PayPal.  Please try another method.', 'paypal-for-woocommerce'));
                 }
                 $error_display_type_message = apply_filters('angelleye_ec_display_type_message', $error_display_type_message, $ErrorCode, $ErrorLongMsg);
                 wc_add_notice($error_display_type_message, 'error');
                 if (!is_ajax()) {
                     wp_redirect(get_permalink(wc_get_page_id('cart')));
                     exit;
                 } else {
                     return;
                 }
             }
         }
     } elseif (isset($_GET['pp_action']) && $_GET['pp_action'] == 'revieworder') {
         wc_clear_notices();
         // The customer has logged into PayPal and approved order.
         // Retrieve the shipping details and present the order for completion.
         if (!defined('WOOCOMMERCE_CHECKOUT')) {
             define('WOOCOMMERCE_CHECKOUT', true);
         }
         $this->add_log('Start Review Order');
         if (isset($_GET['token'])) {
             $token = $_GET['token'];
             $this->set_session('TOKEN', $token);
         }
         if (isset($_GET['PayerID'])) {
             $payerID = $_GET['PayerID'];
             $this->set_session('PayerID', $payerID);
         }
         $this->add_log("...Token:" . $this->get_session('TOKEN'));
         $this->add_log("...PayerID: " . $this->get_session('PayerID'));
         $result = $this->CallGetShippingDetails($this->get_session('TOKEN'));
         if (!empty($result)) {
             $this->set_session('RESULT', serialize($result));
             if (isset($result['SHIPTOCOUNTRYCODE'])) {
                 /**
                  * Check if shiptocountry is in the allowed countries list
                  */
                 if (!array_key_exists($result['SHIPTOCOUNTRYCODE'], WC()->countries->get_allowed_countries())) {
                     wc_add_notice(sprintf(__('We do not sell in your country, please try again with another address.', 'paypal-for-woocommerce')), 'error');
                     wp_redirect(get_permalink(wc_get_page_id('cart')));
                     exit;
                 }
                 WC()->customer->set_shipping_country($result['SHIPTOCOUNTRYCODE']);
             }
             if (isset($result['SHIPTONAME'])) {
                 WC()->customer->shiptoname = $result['SHIPTONAME'];
             }
             if (isset($result['SHIPTOSTREET'])) {
                 WC()->customer->set_address($result['SHIPTOSTREET']);
             }
             if (isset($result['SHIPTOCITY'])) {
                 WC()->customer->set_city($result['SHIPTOCITY']);
             }
             if (isset($result['SHIPTOCOUNTRYCODE'])) {
                 WC()->customer->set_country($result['SHIPTOCOUNTRYCODE']);
             }
             if (isset($result['SHIPTOSTATE'])) {
                 WC()->customer->set_state($this->get_state_code($result['SHIPTOCOUNTRYCODE'], $result['SHIPTOSTATE']));
             }
             if (isset($result['SHIPTOZIP'])) {
                 WC()->customer->set_postcode($result['SHIPTOZIP']);
             }
             if (isset($result['SHIPTOSTATE'])) {
                 WC()->customer->set_shipping_state($this->get_state_code($result['SHIPTOCOUNTRYCODE'], $result['SHIPTOSTATE']));
             }
             if (isset($result['SHIPTOZIP'])) {
                 WC()->customer->set_shipping_postcode($result['SHIPTOZIP']);
             }
             /**
              * Save GECD data in sessions for use in DECP
              */
             $this->set_session('company', isset($result['BUSINESS']) ? $result['BUSINESS'] : '');
             $this->set_session('firstname', isset($result['FIRSTNAME']) ? $result['FIRSTNAME'] : '');
             $this->set_session('lastname', isset($result['LASTNAME']) ? $result['LASTNAME'] : '');
             $this->set_session('shiptoname', isset($result['SHIPTONAME']) ? $result['SHIPTONAME'] : '');
             $this->set_session('shiptostreet', isset($result['SHIPTOSTREET']) ? $result['SHIPTOSTREET'] : '');
             $this->set_session('shiptostreet2', isset($result['SHIPTOSTREET2']) ? $result['SHIPTOSTREET2'] : '');
             $this->set_session('shiptocity', isset($result['SHIPTOCITY']) ? $result['SHIPTOCITY'] : '');
             $this->set_session('shiptocountrycode', isset($result['SHIPTOCOUNTRYCODE']) ? $result['SHIPTOCOUNTRYCODE'] : '');
             $this->set_session('shiptostate', isset($result['SHIPTOSTATE']) ? $result['SHIPTOSTATE'] : '');
             $this->set_session('shiptozip', isset($result['SHIPTOZIP']) ? $result['SHIPTOZIP'] : '');
             $this->set_session('payeremail', isset($result['EMAIL']) ? $result['EMAIL'] : '');
             $this->set_session('giftmessage', isset($result['GIFTMESSAGE']) ? $result['GIFTMESSAGE'] : '');
             $this->set_session('giftreceiptenable', isset($result['GIFTRECEIPTENABLE']) ? $result['GIFTRECEIPTENABLE'] : '');
             $this->set_session('giftwrapname', isset($result['GIFTWRAPNAME']) ? $result['GIFTWRAPNAME'] : '');
             $this->set_session('giftwrapamount', isset($result['GIFTWRAPAMOUNT']) ? $result['GIFTWRAPAMOUNT'] : '');
             $this->set_session('customer_notes', isset($result['PAYMENTREQUEST_0_NOTETEXT']) ? $result['PAYMENTREQUEST_0_NOTETEXT'] : '');
             $this->set_session('phonenum', isset($result['PHONENUM']) ? $result['PHONENUM'] : '');
             WC()->cart->calculate_totals();
         } else {
             $this->add_log("...ERROR: GetShippingDetails returned empty result");
         }
         if ($this->skip_final_review == 'yes' && get_option('woocommerce_enable_guest_checkout') === "yes" && wc_get_page_id('terms') < 0) {
             $url = add_query_arg(array('wc-api' => 'WC_Gateway_PayPal_Express_AngellEYE', 'pp_action' => 'payaction'), home_url());
             wp_redirect($url);
             exit;
         }
         $is_terms_on = get_post_meta($result['INVNUM'], 'paypal_for_woocommerce_terms_on', true);
         if ($this->skip_final_review == 'yes' && get_option('woocommerce_enable_guest_checkout') === "no" && (wc_get_page_id('terms') > 0 && isset($is_terms_on) && !empty($is_terms_on))) {
             $url = add_query_arg(array('wc-api' => 'WC_Gateway_PayPal_Express_AngellEYE', 'pp_action' => 'payaction'), home_url());
             wp_redirect($url);
             exit;
         }
         if (isset($_POST['createaccount'])) {
             $this->customer_id = apply_filters('woocommerce_checkout_customer_id', get_current_user_id());
             if (empty($_POST['username'])) {
                 wc_add_notice(__('Username is required', 'paypal-for-woocommerce'), 'error');
             } elseif (username_exists($_POST['username'])) {
                 wc_add_notice(__('This username is already registered.', 'paypal-for-woocommerce'), 'error');
             } elseif (empty($_POST['email'])) {
                 wc_add_notice(__('Please provide a valid email address.', 'paypal-for-woocommerce'), 'error');
             } elseif (empty($_POST['password']) || empty($_POST['repassword'])) {
                 wc_add_notice(__('Password is required.', 'paypal-for-woocommerce'), 'error');
                 wp_redirect(get_permalink(wc_get_page_id('cart')));
                 exit;
             } elseif ($_POST['password'] != $_POST['repassword']) {
                 wc_add_notice(__('Passwords do not match.', 'paypal-for-woocommerce'), 'error');
             } elseif (get_user_by('email', $_POST['email']) != false) {
                 wc_add_notice(__('This email address is already registered.', 'paypal-for-woocommerce'), 'error');
                 wp_redirect(get_permalink(wc_get_page_id('cart')));
                 exit;
             } else {
                 $username = !empty($_POST['username']) ? $_POST['username'] : '';
                 $password = !empty($_POST['password']) ? $_POST['password'] : '';
                 $email = $_POST['email'];
                 try {
                     // Anti-spam trap
                     if (!empty($_POST['email_2'])) {
                         throw new Exception(__('Anti-spam field was filled in.', 'woocommerce'));
                         wc_add_notice('<strong>' . __('Anti-spam field was filled in.', 'paypal-for-woocommerce') . ':</strong> ', 'error');
                     }
                     $new_customer = wc_create_new_customer(sanitize_email($email), wc_clean($username), $password);
                     if (is_wp_error($new_customer)) {
                         wc_add_notice($user->get_error_message(), 'error');
                     }
                     if (apply_filters('paypal-for-woocommerce_registration_auth_new_customer', true, $new_customer)) {
                         wc_set_customer_auth_cookie($new_customer);
                     }
                     $creds = array('user_login' => wc_clean($username), 'user_password' => $password, 'remember' => true);
                     $user = wp_signon($creds, false);
                     if (is_wp_error($user)) {
                         wc_add_notice($user->get_error_message(), 'error');
                     } else {
                         wp_set_current_user($user->ID);
                         //Here is where we update the global user variables
                         $secure_cookie = is_ssl() ? true : false;
                         wp_set_auth_cookie($user->ID, true, $secure_cookie);
                     }
                 } catch (Exception $e) {
                     wc_add_notice('<strong>' . __('Error', 'paypal-for-woocommerce') . ':</strong> ' . $e->getMessage(), 'error');
                 }
                 $this->customer_id = $user->ID;
                 // As we are now logged in, checkout will need to refresh to show logged in data
                 WC()->session->set('reload_checkout', true);
                 // Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering
                 WC()->cart->calculate_totals();
                 require_once "lib/NameParser.php";
                 $parser = new FullNameParser();
                 $split_name = $parser->split_full_name($result['SHIPTONAME']);
                 $shipping_first_name = $split_name['fname'];
                 $shipping_last_name = $split_name['lname'];
                 $full_name = $split_name['fullname'];
                 // Add customer info from other billing fields
                 if (isset($result)) {
                     update_user_meta($this->customer_id, 'first_name', isset($result['FIRSTNAME']) ? $result['FIRSTNAME'] : '');
                     update_user_meta($this->customer_id, 'last_name', isset($result['LASTNAME']) ? $result['LASTNAME'] : '');
                     update_user_meta($this->customer_id, 'shipping_first_name', $shipping_first_name);
                     update_user_meta($this->customer_id, 'shipping_last_name', $shipping_last_name);
                     update_user_meta($this->customer_id, 'shipping_company', isset($result['BUSINESS']) ? $result['BUSINESS'] : '');
                     update_user_meta($this->customer_id, 'shipping_address_1', isset($result['SHIPTOSTREET']) ? $result['SHIPTOSTREET'] : '');
                     update_user_meta($this->customer_id, 'shipping_address_2', isset($result['SHIPTOSTREET2']) ? $result['SHIPTOSTREET2'] : '');
                     update_user_meta($this->customer_id, 'shipping_city', isset($result['SHIPTOCITY']) ? $result['SHIPTOCITY'] : '');
                     update_user_meta($this->customer_id, 'shipping_postcode', isset($result['SHIPTOZIP']) ? $result['SHIPTOZIP'] : '');
                     update_user_meta($this->customer_id, 'shipping_country', isset($result['SHIPTOCOUNTRYCODE']) ? $result['SHIPTOCOUNTRYCODE'] : '');
                     update_user_meta($this->customer_id, 'shipping_state', isset($result['SHIPTOSTATE']) ? $result['SHIPTOSTATE'] : '');
                     $user_submit_form = maybe_unserialize(WC()->session->checkout_form);
                     if (isset($user_submit_form) && !empty($user_submit_form) && is_array($user_submit_form)) {
                         update_user_meta($this->customer_id, 'billing_first_name', isset($user_submit_form['billing_first_name']) ? $user_submit_form['billing_first_name'] : $result['FIRSTNAME']);
                         update_user_meta($this->customer_id, 'billing_last_name', isset($user_submit_form['billing_last_name']) ? $user_submit_form['billing_last_name'] : $result['LASTNAME']);
                         update_user_meta($this->customer_id, 'billing_address_1', isset($user_submit_form['billing_address_1']) ? $user_submit_form['billing_address_1'] : $result['SHIPTOSTREET']);
                         update_user_meta($this->customer_id, 'billing_address_2', isset($user_submit_form['billing_address_2']) ? $user_submit_form['billing_address_2'] : $result['SHIPTOSTREET2']);
                         update_user_meta($this->customer_id, 'billing_city', isset($user_submit_form['billing_city']) ? $user_submit_form['billing_city'] : $result['SHIPTOCITY']);
                         update_user_meta($this->customer_id, 'billing_postcode', isset($user_submit_form['billing_postcode']) ? $user_submit_form['billing_postcode'] : $result['SHIPTOZIP']);
                         update_user_meta($this->customer_id, 'billing_country', isset($user_submit_form['billing_country']) ? $user_submit_form['billing_country'] : $result['SHIPTOCOUNTRYCODE']);
                         update_user_meta($this->customer_id, 'billing_state', isset($user_submit_form['billing_state']) ? $user_submit_form['billing_state'] : $result['SHIPTOSTATE']);
                         update_user_meta($this->customer_id, 'billing_phone', isset($user_submit_form['billing_phone']) ? $user_submit_form['billing_phone'] : $result['PHONENUM']);
                         update_user_meta($this->customer_id, 'billing_email', isset($user_submit_form['billing_email']) ? $user_submit_form['billing_email'] : $result['EMAIL']);
                     } else {
                         update_user_meta($this->customer_id, 'billing_first_name', $shipping_first_name);
                         update_user_meta($this->customer_id, 'billing_last_name', $shipping_last_name);
                         update_user_meta($this->customer_id, 'billing_address_1', isset($result['SHIPTOSTREET']) ? $result['SHIPTOSTREET'] : '');
                         update_user_meta($this->customer_id, 'billing_address_2', isset($result['SHIPTOSTREET2']) ? $result['SHIPTOSTREET2'] : '');
                         update_user_meta($this->customer_id, 'billing_city', isset($result['SHIPTOCITY']) ? $result['SHIPTOCITY'] : '');
                         update_user_meta($this->customer_id, 'billing_postcode', isset($result['SHIPTOZIP']) ? $result['SHIPTOZIP'] : '');
                         update_user_meta($this->customer_id, 'billing_country', isset($result['SHIPTOCOUNTRYCODE']) ? $result['SHIPTOCOUNTRYCODE'] : '');
                         update_user_meta($this->customer_id, 'billing_state', isset($result['SHIPTOSTATE']) ? $result['SHIPTOSTATE'] : '');
                         update_user_meta($this->customer_id, 'billing_phone', isset($result['PHONENUM']) ? $result['PHONENUM'] : '');
                         update_user_meta($this->customer_id, 'billing_email', isset($result['EMAIL']) ? $result['EMAIL'] : '');
                     }
                 }
             }
         }
     } elseif (isset($_GET['pp_action']) && $_GET['pp_action'] == 'payaction') {
         if (isset($_POST) || $this->skip_final_review == 'yes' && get_option('woocommerce_enable_guest_checkout') === "yes") {
             // Update customer shipping and payment method to posted method
             $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
             if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method'])) {
                 foreach ($_POST['shipping_method'] as $i => $value) {
                     $chosen_shipping_methods[$i] = wc_clean($value);
                 }
                 if (isset($value) && !empty($value)) {
                     $selected_shipping_method = wc_clean($value);
                 }
                 WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
             }
             if (WC()->cart->needs_shipping()) {
                 // Validate Shipping Methods
                 $packages = WC()->shipping->get_packages();
                 WC()->checkout()->shipping_methods = WC()->session->get('chosen_shipping_methods');
             }
             $this->add_log('Start Pay Action');
             if (!defined('WOOCOMMERCE_CHECKOUT')) {
                 define('WOOCOMMERCE_CHECKOUT', true);
             }
             WC()->cart->calculate_totals();
             $resultarray = array();
             $resultarray = maybe_unserialize(WC()->session->result);
             $order_id = $resultarray['PAYMENTS'][0]['INVNUM'];
             /**
              * Update meta data with session data
              */
             // Parse SHIPTONAME to fist and last name
             require_once "lib/NameParser.php";
             $parser = new FullNameParser();
             $split_name = $parser->split_full_name($this->get_session('shiptoname'));
             $shipping_first_name = $split_name['fname'];
             $shipping_last_name = $split_name['lname'];
             $full_name = $split_name['fullname'];
             $this->set_session('firstname', isset($result['FIRSTNAME']) ? $result['FIRSTNAME'] : $shipping_first_name);
             $this->set_session('lastname', isset($result['LASTNAME']) ? $result['LASTNAME'] : $shipping_last_name);
             /* create account start */
             if (isset($_POST['create_act']) && !empty($_POST['create_act'])) {
                 $this->customer_id = apply_filters('woocommerce_checkout_customer_id', get_current_user_id());
                 $create_user_email = $resultarray['EMAIL'];
                 //$create_user_name = $full_name;
                 $create_user_name = sanitize_user(current(explode('@', $create_user_email)), true);
                 // Ensure username is unique
                 $append = 1;
                 $o_username = $create_user_name;
                 while (username_exists($create_user_name)) {
                     $create_user_name = $o_username . $append;
                     $append++;
                 }
                 if (empty($create_user_name)) {
                     wc_add_notice(__('Username is required', 'paypal-for-woocommerce'), 'error');
                     wp_redirect(get_permalink(wc_get_page_id('cart')));
                     exit;
                 } elseif (username_exists($create_user_name)) {
                     wc_add_notice(__('This username is already registered.', 'paypal-for-woocommerce'), 'error');
                     wp_redirect(get_permalink(wc_get_page_id('cart')));
                     exit;
                 } elseif (empty($create_user_email)) {
                     wc_add_notice(__('Please provide a valid email address.', 'paypal-for-woocommerce'), 'error');
                     wp_redirect(get_permalink(wc_get_page_id('cart')));
                     exit;
                 } elseif (empty($_POST['create_act']) || empty($_POST['create_act'])) {
                     wc_add_notice(__('Password is required.', 'paypal-for-woocommerce'), 'error');
                     wp_redirect(get_permalink(wc_get_page_id('cart')));
                     exit;
                 } elseif ($_POST['create_act'] != $_POST['create_act']) {
                     wc_add_notice(__('Passwords do not match.', 'paypal-for-woocommerce'), 'error');
                     wp_redirect(get_permalink(wc_get_page_id('cart')));
                     exit;
                 } elseif (get_user_by('email', $create_user_email) != false) {
                     wc_add_notice(__('This email address is already registered.', 'paypal-for-woocommerce'), 'error');
                     wp_redirect(get_permalink(wc_get_page_id('cart')));
                     exit;
                 } else {
                     $username = !empty($create_user_name) ? $create_user_name : '';
                     $password = !empty($_POST['create_act']) ? $_POST['create_act'] : '';
                     $email = $create_user_email;
                     try {
                         // Anti-spam trap
                         if (!empty($_POST['email_2'])) {
                             throw new Exception(__('Anti-spam field was filled in.', 'woocommerce'));
                             wc_add_notice('<strong>' . __('Anti-spam field was filled in.', 'paypal-for-woocommerce') . ':</strong> ', 'error');
                         }
                         $new_customer = wc_create_new_customer(sanitize_email($email), wc_clean($username), $password);
                         if (is_wp_error($new_customer)) {
                             wc_add_notice($user->get_error_message(), 'error');
                         }
                         if (apply_filters('paypal-for-woocommerce_registration_auth_new_customer', true, $new_customer)) {
                             wc_set_customer_auth_cookie($new_customer);
                         }
                         $creds = array('user_login' => wc_clean($username), 'user_password' => $password, 'remember' => true);
                         $user = wp_signon($creds, false);
                         if (is_wp_error($user)) {
                             wc_add_notice($user->get_error_message(), 'error');
                             wp_redirect(get_permalink(wc_get_page_id('cart')));
                             exit;
                         } else {
                             wp_set_current_user($user->ID);
                             //Here is where we update the global user variables
                             $secure_cookie = is_ssl() ? true : false;
                             wp_set_auth_cookie($user->ID, true, $secure_cookie);
                         }
                     } catch (Exception $e) {
                         wc_add_notice('<strong>' . __('Error', 'paypal-for-woocommerce') . ':</strong> ' . $e->getMessage(), 'error');
                     }
                     $this->customer_id = $user->ID;
                 }
             }
             update_post_meta($order_id, '_payment_method', $this->id);
             update_post_meta($order_id, '_payment_method_title', $this->title);
             if (is_user_logged_in()) {
                 $userLogined = wp_get_current_user();
                 update_post_meta($order_id, '_billing_email', $userLogined->user_email);
                 update_post_meta($order_id, '_customer_user', $userLogined->ID);
             } else {
                 update_post_meta($order_id, '_billing_email', $this->get_session('payeremail'));
             }
             $checkout_form_data = maybe_unserialize($this->get_session('checkout_form'));
             if (isset($this->billing_address) && $this->billing_address == 'yes' && empty($checkout_form_data['billing_country'])) {
                 $checkout_form_data = array();
             }
             if (isset($checkout_form_data) && !empty($checkout_form_data)) {
                 foreach ($checkout_form_data as $key => $value) {
                     if (strpos($key, 'billing_') !== false && !empty($value) && !is_array($value)) {
                         if ($checkout_form_data['ship_to_different_address'] == false) {
                             $shipping_key = str_replace('billing_', 'shipping_', $key);
                             update_user_meta($this->customer_id, $shipping_key, $value);
                             update_post_meta($order_id, '_' . $shipping_key, $value);
                         }
                         update_user_meta($this->customer_id, $key, $value);
                         update_post_meta($order_id, '_' . $key, $value);
                     } elseif (WC()->cart->needs_shipping() && strpos($key, 'shipping_') !== false && !empty($value) && !is_array($value)) {
                         update_user_meta($this->customer_id, $key, $value);
                         update_post_meta($order_id, '_' . $key, $value);
                     }
                 }
                 do_action('woocommerce_checkout_update_user_meta', $this->customer_id, $checkout_form_data);
             } else {
                 update_post_meta($order_id, '_shipping_first_name', $this->get_session('firstname'));
                 update_post_meta($order_id, '_shipping_last_name', $this->get_session('lastname'));
                 update_post_meta($order_id, '_shipping_full_name', $full_name);
                 update_post_meta($order_id, '_shipping_company', $this->get_session('company'));
                 update_post_meta($order_id, '_billing_phone', $this->get_session('phonenum'));
                 update_post_meta($order_id, '_shipping_address_1', $this->get_session('shiptostreet'));
                 update_post_meta($order_id, '_shipping_address_2', $this->get_session('shiptostreet2'));
                 update_post_meta($order_id, '_shipping_city', $this->get_session('shiptocity'));
                 update_post_meta($order_id, '_shipping_postcode', $this->get_session('shiptozip'));
                 update_post_meta($order_id, '_shipping_country', $this->get_session('shiptocountrycode'));
                 update_post_meta($order_id, '_shipping_state', $this->get_state_code($this->get_session('shiptocountrycode'), $this->get_session('shiptostate')));
                 update_post_meta($order_id, '_customer_user', get_current_user_id());
                 if ($this->billing_address == 'yes') {
                     update_post_meta($order_id, '_billing_first_name', $this->get_session('firstname'));
                     update_post_meta($order_id, '_billing_last_name', $this->get_session('lastname'));
                     update_post_meta($order_id, '_billing_full_name', $full_name);
                     update_post_meta($order_id, '_billing_company', $this->get_session('company'));
                     update_post_meta($order_id, '_billing_address_1', $this->get_session('shiptostreet'));
                     update_post_meta($order_id, '_billing_address_2', $this->get_session('shiptostreet2'));
                     update_post_meta($order_id, '_billing_city', $this->get_session('shiptocity'));
                     update_post_meta($order_id, '_billing_postcode', $this->get_session('shiptozip'));
                     update_post_meta($order_id, '_billing_country', $this->get_session('shiptocountrycode'));
                     update_post_meta($order_id, '_billing_state', $this->get_state_code($this->get_session('shiptocountrycode'), $this->get_session('shiptostate')));
                 }
             }
             $this->add_log('...Order ID: ' . $order_id);
             $order = new WC_Order($order_id);
             do_action('woocommerce_ppe_do_payaction', $order);
             $this->add_log('...Order Total: ' . $order->order_total);
             $this->add_log('...Cart Total: ' . WC()->cart->get_total());
             $this->add_log("...Token:" . $this->get_session('TOKEN'));
             $result = $this->ConfirmPayment($order->order_total);
             // Set Customer Name
             if (!get_current_user_id()) {
                 update_post_meta($order_id, '_billing_first_name', $this->get_session('firstname'));
                 update_post_meta($order_id, '_billing_last_name', $this->get_session('lastname'));
             }
             /**
              * Customer Notes
              */
             if ($this->get_session('customer_notes') != '') {
                 //  $order->add_order_note(__('Customer Notes: ', 'paypal-for-woocommerce') . $this->get_session('customer_notes'));
                 $checkout_note = array('ID' => $order_id, 'post_excerpt' => $this->get_session('customer_notes'));
                 wp_update_post($checkout_note);
                 $checkout_form_data['order_comments'] = '';
                 unset($checkout_form_data['order_comments']);
             }
             if (isset($checkout_form_data) && !empty($checkout_form_data['order_comments'])) {
                 // Update post 37
                 $checkout_note = array('ID' => $order_id, 'post_excerpt' => $checkout_form_data['order_comments']);
                 wp_update_post($checkout_note);
                 $checkout_form_data['order_comments'] = '';
                 unset($checkout_form_data['order_comments']);
             }
             // Update the post into the database
             if (isset($my_post) && !empty($my_post)) {
                 wp_update_post($my_post);
             }
             if ($result['ACK'] == 'Success' || $result['ACK'] == 'SuccessWithWarning') {
                 $this->add_log('Payment confirmed with PayPal successfully');
                 $result = apply_filters('woocommerce_payment_successful_result', $result);
                 /**
                  * Gift Wrap Notes
                  */
                 if ($this->get_session('giftwrapamount') != '') {
                     $giftwrap_note = __('Gift Wrap Added', 'paypal-for-woocommerce');
                     $giftwrap_note .= $this->get_session('giftwrapname') != '' ? ' - ' . $this->get_session('giftwrapname') : '';
                     $giftwrap_note .= $this->get_session('giftmessage') != '' ? '<br />Message: ' . $this->get_session('giftmessage') : '';
                     $giftwrap_note .= '<br />' . __('Use Gift Receipt?: ', 'paypal-for-woocommerce');
                     $giftwrap_note .= strtolower($this->get_session('giftreceiptenable')) == 'true' ? 'Yes' : 'No';
                     //$giftwrap_note .= '<br />Fee: ' . woocommerce_price(number_format($this->get_session('giftwrapamount'),2));
                     $order->add_order_note($giftwrap_note);
                 }
                 $order->add_order_note(__('PayPal Express payment completed', 'paypal-for-woocommerce') . ' ( Response Code: ' . $result['ACK'] . ", " . ' TransactionID: ' . $result['PAYMENTINFO_0_TRANSACTIONID'] . ' )');
                 $REVIEW_RESULT = unserialize($this->get_session('RESULT'));
                 $payerstatus_note = __('Payer Status: ', 'paypal-for-woocommerce');
                 $payerstatus_note .= ucfirst($REVIEW_RESULT['PAYERSTATUS']);
                 $order->add_order_note($payerstatus_note);
                 $addressstatus_note = __('Address Status: ', 'paypal-for-woocommerce');
                 $addressstatus_note .= ucfirst($REVIEW_RESULT['ADDRESSSTATUS']);
                 $order->add_order_note($addressstatus_note);
                 $order->payment_complete($result['PAYMENTINFO_0_TRANSACTIONID']);
                 //add hook
                 do_action('woocommerce_checkout_order_processed', $order_id);
                 // Empty the Cart
                 WC()->cart->empty_cart();
                 /* if (isset($this->get_session('customer_notes')) && !empty($this->get_session('customer_notes'))) {
                 			$this->get_session('customer_notes') == '';
                 			} */
                 global $wpdb, $table_prefix;
                 $table_name = $table_prefix . "woocommerce_order_items";
                 $table_name_meta = $table_prefix . "woocommerce_order_itemmeta";
                 $get_exits_record = $wpdb->get_row("select count(*)as cnt from {$table_name} where order_id='{$order_id}' and order_item_type ='shipping'");
                 $count_record = $get_exits_record->cnt;
                 if (isset($selected_shipping_method) && !empty($selected_shipping_method)) {
                     $selected_shipping_method_id = $selected_shipping_method;
                 } else {
                     $selected_shipping_method_id = '';
                 }
                 if (isset($resultarray['SHIPPINGAMT']) && !empty($resultarray['SHIPPINGAMT'])) {
                     if (isset($count_record) && empty($count_record) && $count_record <= 0) {
                         $wpdb->query($wpdb->prepare("INSERT INTO {$table_name}(order_item_name, order_item_type,order_id )VALUES (%s, %s, %s )", $selected_shipping_method_id, 'shipping', $order_id));
                         $shipping_amt = $resultarray['SHIPPINGAMT'];
                         $get_metadataid = $wpdb->get_row("select * from {$table_name} where order_id='{$order_id}' and order_item_type ='shipping'");
                         $order_itemid = $get_metadataid->order_item_id;
                         wc_add_order_item_meta($order_itemid, 'method_id', $selected_shipping_method_id);
                         wc_add_order_item_meta($order_itemid, 'cost', wc_format_decimal($shipping_amt));
                         $shipping_post_meta = get_post_meta($order_id, 'shipping_taxamt_own', true);
                         if (isset($shipping_post_meta) && !empty($shipping_post_meta)) {
                             wc_add_order_item_meta($order_itemid, 'shipping_tax_amount', round($shipping_post_meta, 2));
                         }
                         $get_shippingtaxamt = $wpdb->get_row("select * from {$table_name_meta} where order_item_id='{$order_itemid}' and meta_key ='shipping_tax_amount'");
                         if (isset($get_shippingtaxamt->meta_value) && !empty($get_shippingtaxamt->meta_value)) {
                             $get_shippingtaxamtkey_amt = round($get_shippingtaxamt->meta_value, 2);
                         }
                         if (isset($get_shippingtaxamtkey_amt) && !empty($get_shippingtaxamtkey_amt)) {
                             $shippingtaxamt = 'a:1:{i:1;s:10:"' . $get_shippingtaxamtkey_amt . '";}';
                         } else {
                             $shippingtaxamt = 'a:1:{i:1;s:10:"0.00";}';
                         }
                         wc_add_order_item_meta($order_itemid, 'taxes', $shippingtaxamt);
                     }
                 }
                 wp_redirect($this->get_return_url($order));
                 exit;
             } else {
                 $this->add_log('...Error confirming order ' . $order_id . ' with PayPal');
                 $this->add_log('...response:' . print_r($result, true));
                 // Display a user friendly Error on the page and log details
                 $ErrorCode = urldecode($result["L_ERRORCODE0"]);
                 $ErrorShortMsg = urldecode($result["L_SHORTMESSAGE0"]);
                 $ErrorLongMsg = urldecode($result["L_LONGMESSAGE0"]);
                 $ErrorSeverityCode = urldecode($result["L_SEVERITYCODE0"]);
                 $this->add_log('SetExpressCheckout API call failed. ');
                 $this->add_log('Detailed Error Message: ' . $ErrorLongMsg);
                 $this->add_log('Short Error Message: ' . $ErrorShortMsg);
                 $this->add_log('Error Code: ' . $ErrorCode);
                 $this->add_log('Error Severity Code: ' . $ErrorSeverityCode);
                 if ($ErrorCode == '10486') {
                     $this->RedirectToPayPal($this->get_session('TOKEN'));
                 }
                 // Notice admin if has any issue from PayPal
                 $message = '';
                 if ($this->error_email_notify) {
                     $admin_email = get_option("admin_email");
                     $message .= __("DoExpressCheckoutPayment API call failed.", "paypal-for-woocommerce") . "\n\n";
                     $message .= __('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode . "\n";
                     $message .= __('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode . "\n";
                     $message .= __('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg . "\n";
                     $message .= __('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg . "\n";
                     $message .= __('Order ID: ') . $order_id . "\n";
                     $message .= __('Customer Name: ') . $this->get_session('shiptoname') . "\n";
                     $message .= __('Customer Email: ') . $this->get_session('payeremail') . "\n";
                     $error_email_notify_mes = apply_filters('angelleye_ec_error_email_notify_message', $message, $ErrorCode, $ErrorSeverityCode, $ErrorShortMsg, $ErrorLongMsg);
                     $subject = "PayPal Express Checkout Error Notification";
                     $error_email_notify_subject = apply_filters('angelleye_ec_error_email_notify_subject', $subject);
                     wp_mail($admin_email, $error_email_notify_subject, $error_email_notify_mes);
                 }
                 // Generate error message based on Error Display Type setting
                 if ($this->error_display_type == 'detailed') {
                     $sec_error_notice = $ErrorCode . ' - ' . $ErrorLongMsg;
                     $error_display_type_message = sprintf(__($sec_error_notice, 'paypal-for-woocommerce'));
                 } else {
                     $error_display_type_message = sprintf(__('There was a problem paying with PayPal.  Please try another method.', 'paypal-for-woocommerce'));
                 }
                 $error_display_type_message = apply_filters('angelleye_ec_display_type_message', $error_display_type_message, $ErrorCode, $ErrorLongMsg);
                 wc_add_notice($error_display_type_message, 'error');
                 wp_redirect(get_permalink(wc_get_page_id('cart')));
                 exit;
             }
         }
     }
 }
 /**
  *
  *
  * @param unknown $user_id
  */
 public function save_pending($user_id)
 {
     if (isset($_POST['apply_for_vendor'])) {
         wc_clear_notices();
         if (user_can($user_id, 'manage_options')) {
             wc_add_notice(apply_filters('wcvendors_application_denied_msg', __('Application denied. You are an administrator.', 'wcvendors')), 'error');
         } else {
             wc_add_notice(apply_filters('wcvendors_application_submitted_msg', __('Your application has been submitted.', 'wcvendors')), 'notice');
             $manual = WC_Vendors::$pv_options->get_option('manual_vendor_registration');
             $role = apply_filters('wcvendors_pending_role', $manual ? 'pending_vendor' : 'vendor');
             $wp_user_object = new WP_User($user_id);
             $wp_user_object->set_role($role);
             do_action('wcvendors_application_submited', $user_id);
             add_filter('woocommerce_registration_redirect', array($this, 'redirect_to_vendor_dash'));
         }
     }
 }
Esempio n. 9
0
function apply_membership_benifits()
{
    global $woocommerce;
    $level = get_user_info('loyalty_status');
    $total = floatval(preg_replace('#[^\\d.]#', '', $woocommerce->cart->get_cart_total()));
    if ($level == 'Green' || $woocommerce->cart->has_discount($level)) {
        return;
    } elseif ($total < 3660) {
        /* echo'<div class="woocommerce-error">The minimum spend for membership discounts is $60.00.</div>'; */
    } else {
        $woocommerce->cart->add_discount($level);
        echo '<div class="woocommerce-message">Membership discount applied successfully.</div>';
        wc_clear_notices();
    }
}
Esempio n. 10
0
function redirect_to_checkout()
{
    wc_clear_notices();
    return WC()->cart->get_checkout_url();
}
 /**
  * Process payment
  * @param $order_id
  * @param $data
  */
 public function process_payment($order_id, $data)
 {
     if (!isset($data['payment_details'])) {
         return;
     }
     // some gateways check if a user is signed in, so let's switch to customer
     $logged_in_user = get_current_user_id();
     $customer_id = isset($data['customer_id']) ? $data['customer_id'] : 0;
     wp_set_current_user($customer_id);
     // load the gateways & process payment
     $gateway_id = $data['payment_details']['method_id'];
     add_filter('option_woocommerce_' . $gateway_id . '_settings', array($this, 'force_enable_gateway'));
     $settings = WC_POS_Admin_Settings_Checkout::get_instance();
     $gateways = $settings->load_enabled_gateways();
     $response = $gateways[$gateway_id]->process_payment($order_id);
     if (isset($response['result']) && $response['result'] == 'success') {
         $this->payment_success($gateway_id, $order_id, $response);
     } else {
         $this->payment_failure($gateway_id, $order_id, $response);
     }
     // switch back to logged in user
     wp_set_current_user($logged_in_user);
     // clear any payment gateway messages
     wc_clear_notices();
 }
Esempio n. 12
0
<?php

include_once 'front_template.php';
$obj = new Frontpage();
$obj->checkLogin();
wc_clear_notices();
if (isset($_GET['key']) && $_GET['key'] != '') {
    $_SESSION['checkout'] = 'Done';
    if (get_option('_skip_ga_ecommerce') == 1) {
        $url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
        $template_name = strpos($url, '/order-received/') === false ? '/view-order/' : '/order-received/';
        if (strpos($url, $template_name) !== false) {
            $start = strpos($url, $template_name);
            $first_part = substr($url, $start + strlen($template_name));
            $order_id = substr($first_part, 0, strpos($first_part, '/'));
            //yes, I can retrieve the order via the order id
            $order = new WC_Order($order_id);
            $items_details = $order->get_items();
            $items = array();
            $i = 0;
            foreach ($items_details as $item) {
                //print_r($item);
                $product = $order->get_product_from_item($item);
                $product_id = $item['product_id'];
                $term_list = wp_get_post_terms($product_id, 'product_cat', array('fields' => 'ids'));
                $cat_id = (int) $term_list[0];
                $category = get_term($cat_id, 'product_cat');
                $items[$i]['name'] = $item['name'];
                $items[$i]['quantity'] = $item['qty'];
                $items[$i]['sku'] = $product->get_sku();
                $items[$i]['price'] = $product->get_price();
 /**
  *
  *
  * @return unknown
  */
 public function apply_form()
 {
     global $woocommerce;
     if (!isset($_POST['apply_for_vendor'])) {
         return false;
     }
     if ($this->terms_page && !isset($_POST['agree_to_terms'])) {
         wc_clear_notices();
         wc_add_notice(__('You must accept the terms and conditions to become a vendor.', 'wcvendors'), 'error');
     } else {
         if (isset($_POST['apply_for_vendor_submit'])) {
             self::save_pending(get_current_user_id());
         }
     }
 }
 /**
  * For a smoother sign up process, tell WooCommerce to redirect the shopper immediately to
  * the checkout page after she clicks the "Sign Up Now" button
  *
  * Only enabled if multiple checkout is not enabled.
  *
  * @param string $url The cart redirect $url WooCommerce determined.
  * @since 1.0
  */
 public static function add_to_cart_redirect($url)
 {
     // If product is of the subscription type
     if (is_numeric($_REQUEST['add-to-cart']) && WC_Subscriptions_Product::is_subscription((int) $_REQUEST['add-to-cart']) && 'yes' != get_option(WC_Subscriptions_Admin::$option_prefix . '_multiple_purchase', 'no')) {
         wc_clear_notices();
         // Redirect to checkout
         $url = WC()->cart->get_checkout_url();
     }
     return $url;
 }
Esempio n. 15
0
 /**
  * For a smoother sign up process, tell WooCommerce to redirect the shopper immediately to
  * the checkout page after she clicks the "Sign Up Now" button
  *
  * Only enabled if multiple checkout is not enabled.
  *
  * @param string $url The cart redirect $url WooCommerce determined.
  * @since 1.0
  */
 public static function add_to_cart_redirect($url)
 {
     // If product is of the subscription type
     if (isset($_REQUEST['add-to-cart']) && is_numeric($_REQUEST['add-to-cart']) && WC_Subscriptions_Product::is_subscription((int) $_REQUEST['add-to-cart'])) {
         // Redirect to checkout if mixed checkout is disabled
         if ('yes' != get_option(WC_Subscriptions_Admin::$option_prefix . '_multiple_purchase', 'no')) {
             wc_clear_notices();
             $url = WC()->cart->get_checkout_url();
             // Redirect to the same page (if the customer wouldn't be redirected to the cart) to ensure the cart widget loads correctly
         } elseif ('yes' != get_option('woocommerce_cart_redirect_after_add')) {
             $url = remove_query_arg('add-to-cart');
         }
     }
     return $url;
 }
Esempio n. 16
0
function get_notices()
{
    if (!did_action('woocommerce_init')) {
        _doing_it_wrong(__FUNCTION__, __('This function should not be called before woocommerce_init.', 'woocommerce'), '2.3');
        return;
    }
    $all_notices = WC()->session->get('wc_notices', array());
    $notice_types = apply_filters('woocommerce_notice_types', array('error', 'success', 'notice'));
    $notice_arr = array();
    foreach ($notice_types as $notice_type) {
        if (wc_notice_count($notice_type) > 0) {
            $notice_arr[$notice_type] = $all_notices[$notice_type];
        }
    }
    wc_clear_notices();
    return json_encode($notice_arr);
}
Esempio n. 17
0
 /**
  * Action to perform when offer is accepted
  */
 function action_on_accept_offer($post_id, $page, $parent_offer_id, $variation_data)
 {
     global $current_user, $sa_smart_offers;
     $source = !empty($_GET['source']) ? $_GET['source'] : null;
     $so_offers = new SO_Offers();
     $current_offer_id = $_GET['so_offer_id'];
     list($where, $where_url) = $so_offers->get_page_details();
     if (strpos($where_url, 'so_action=skip') || strpos($where_url, 'so_action=accept')) {
         $where_url = esc_url(remove_query_arg(array('so_action', 'so_offer_id', 'source'), $where_url));
     }
     list($accepted_session_variable, $accepted_ids_in_session) = $so_offers->get_accepted_offer_ids_from_session();
     list($skipped_session_variable, $skipped_ids_in_session) = $so_offers->get_skipped_offer_ids_from_session();
     $skip_offer_id_variable = $where == "any" ? str_replace(array('/', '-', '&', '=', ':'), '', $where_url) . '_skip_offer_id' : $where . '_skip_offer_id';
     list($offer_id_on_skipping, $skipped_offer_id_variable) = $so_offers->get_offer_id_on_skipping($skip_offer_id_variable);
     $parent_offer_id_variable = $where == "any" ? str_replace(array('/', '-', '&', '=', ':'), '', $where_url) . '_parent_offer_id' : $where . '_parent_offer_id';
     $check_parent_offer_id_set_or_not = SO_Session_Handler::check_session_set_or_not($parent_offer_id_variable);
     if (!$check_parent_offer_id_set_or_not) {
         SO_Session_Handler::so_set_session_variables($parent_offer_id_variable, $current_offer_id);
     }
     if (isset($variation_data['variation_id']) && $variation_data['variation_id'] != '') {
         $target_product_id = $variation_data['variation_id'];
     } else {
         $target_product_id = get_post_meta($post_id, 'target_product_ids', true);
     }
     $quantity = isset($variation_data['quantity']) && !empty($variation_data['quantity']) ? $variation_data['quantity'] : 1;
     if (!empty($target_product_id)) {
         if (isset($variation_data['variation_id']) && $variation_data['variation_id'] != '') {
             $all_variations_set = true;
             $parent_id = $variation_data['parent_prod_id'];
             $adding_to_cart = $sa_smart_offers->get_product($parent_id);
             //get_product( $parent_id );
             $attributes = $adding_to_cart->get_attributes();
             $variation_id = $variation_data['variation_id'];
             $variation_instance = $sa_smart_offers->get_product($variation_id);
             //get_product( $variation_id );
             foreach ($attributes as $attribute) {
                 if (!$attribute['is_variation']) {
                     continue;
                 }
                 $taxonomy = 'attribute_' . sanitize_title($attribute['name']);
                 if (!empty($_POST[$taxonomy])) {
                     // Get value from post data
                     // Don't use woocommerce_clean as it destroys sanitized characters
                     $value = sanitize_title(trim(stripslashes($_POST[$taxonomy])));
                     // Get valid value from variation
                     $valid_value = $variation_instance->variation_data[$taxonomy];
                     // Allow if valid
                     if ($valid_value == '' || $valid_value == $value) {
                         if ($attribute['is_taxonomy']) {
                             $variation[esc_html($attribute['name'])] = $value;
                         } else {
                             // For custom attributes, get the name from the slug
                             $options = array_map('trim', explode('|', $attribute['value']));
                             foreach ($options as $option) {
                                 if (sanitize_title($option) == $value) {
                                     $value = $option;
                                     break;
                                 }
                             }
                             $variation[esc_html($attribute['name'])] = $value;
                         }
                         continue;
                     }
                 }
                 $all_variations_set = false;
             }
         } else {
             $target_product_instance = $sa_smart_offers->get_product($target_product_id);
             if (isset($target_product_instance->variation_id)) {
                 $parent_id = $target_product_instance->id;
                 $variation_id = $target_product_instance->variation_id;
                 $variation = $target_product_instance->variation_data;
             } else {
                 $parent_id = $target_product_instance->id;
                 $variation_id = '';
                 $variation = '';
             }
         }
         // Storing offer rules of parent in case of skipped offers
         if (!empty($parent_offer_id) || ($page == "cart_page" || $page == "checkout_page" || $page == "myaccount_page" || $page == "home_page" || $page == "post_checkout_page" || $page == "any_page")) {
             $offer_rules = get_post_meta($post_id, '_offer_rules', true);
         }
         $action_on_accept = get_post_meta($post_id, 'so_actions_on_accept', true);
         $products_to_be_removed = array();
         if (!empty($action_on_accept)) {
             if (isset($action_on_accept['remove_prods_from_cart'])) {
                 $products_to_be_removed = !empty($action_on_accept['remove_prods_from_cart']) ? explode(',', $action_on_accept['remove_prods_from_cart']) : array();
             }
         }
         if (in_array('all', $products_to_be_removed)) {
             $sa_smart_offers->global_wc()->cart->empty_cart();
             $products_to_be_removed = array();
         }
         if (!empty($offer_rules)) {
             foreach ($offer_rules as $key => $val) {
                 if ($val["offer_action"] == "cart_contains") {
                     $cart_contains = $val['offer_rule_value'];
                 }
             }
             $cart_contains = isset($cart_contains) ? explode(",", $cart_contains) : array();
             if (!empty($products_to_be_removed)) {
                 foreach ($products_to_be_removed as $prod_ids) {
                     $prod_parent_id = wp_get_post_parent_id($prod_ids);
                     if (!empty($prod_parent_id)) {
                         $products_to_be_removed[] = $prod_parent_id;
                     }
                 }
             }
             $cart_contains_item_key = array();
             $keys_of_products_removed = array();
             if (!empty($cart_contains)) {
                 if (count($products_to_be_removed) > 0) {
                     $cart_contains = array_diff($cart_contains, $products_to_be_removed);
                 }
                 foreach ($cart_contains as $id) {
                     foreach ($sa_smart_offers->global_wc()->cart->cart_contents as $key => $values) {
                         if ($id == $values['product_id'] || $id == $values['variation_id']) {
                             $cart_contains_item_key[] = $key;
                         }
                     }
                 }
             }
             if (count($products_to_be_removed) > 0) {
                 foreach ($products_to_be_removed as $p_id) {
                     foreach ($sa_smart_offers->global_wc()->cart->cart_contents as $key => $values) {
                         if ($p_id == $values['product_id'] || $p_id == $values['variation_id']) {
                             $keys_of_products_removed[] = $key;
                         }
                     }
                 }
             }
             if (!empty($keys_of_products_removed)) {
                 if (count($cart_contains_item_key) > 0) {
                     $cart_contains_item_key = array_diff($cart_contains_item_key, $keys_of_products_removed);
                 }
                 if (count($cart_contains) < 0) {
                     $cart_contains = array();
                 }
                 if (count($cart_contains_item_key) < 0) {
                     $cart_contains_item_key = array();
                 }
                 if (isset($parent_offer_id) && !empty($parent_offer_id)) {
                     $parent_offer_ids = array();
                     array_push($parent_offer_ids, $parent_offer_id);
                 } else {
                     $parent_offer_ids = array();
                 }
                 $cart = $sa_smart_offers->global_wc()->cart->cart_contents;
                 foreach ($keys_of_products_removed as $cart_key) {
                     if (isset($cart[$cart_key]['smart_offers'])) {
                         if (is_array($cart[$cart_key]['smart_offers']['cart_contains_keys']) && count($cart[$cart_key]['smart_offers']['cart_contains_keys']) > 0) {
                             $cart_contains_item_key = array_unique(array_merge($cart_contains_item_key, $cart[$cart_key]['smart_offers']['cart_contains_keys']));
                         }
                         if (is_array($cart[$cart_key]['smart_offers']['cart_contains_ids']) && count($cart[$cart_key]['smart_offers']['cart_contains_ids']) > 0) {
                             $cart_contains = array_unique(array_merge($cart_contains, $cart[$cart_key]['smart_offers']['cart_contains_ids']));
                         }
                         if (isset($cart[$cart_key]['smart_offers']['parent_offer_id']) && !empty($cart[$cart_key]['smart_offers']['parent_offer_id'])) {
                             if (is_array($cart[$cart_key]['smart_offers']['parent_offer_id'])) {
                                 $parent_offer_id = array_unique(array_merge($parent_offer_ids, $cart[$cart_key]['smart_offers']['parent_offer_id']));
                             } else {
                                 array_push($parent_offer_ids, $cart[$cart_key]['smart_offers']['parent_offer_id']);
                             }
                         }
                     }
                     unset($sa_smart_offers->global_wc()->cart->cart_contents[$cart_key]);
                 }
                 if (is_array($parent_offer_ids) && count($parent_offer_ids) > 0) {
                     $parent_offer_id = $parent_offer_ids;
                 }
             }
             if (!empty($cart_contains) && is_array($cart_contains) && !empty($cart_contains_item_key)) {
                 $args['smart_offers'] = array('accept_offer' => true, 'offer_id' => $post_id, 'accepted_from' => $page, 'cart_contains_keys' => $cart_contains_item_key, 'cart_contains_ids' => $cart_contains);
             } else {
                 $args['smart_offers'] = array('accept_offer' => true, 'offer_id' => $post_id, 'accepted_from' => $page);
             }
         } else {
             $args['smart_offers'] = array('accept_offer' => true, 'offer_id' => $post_id, 'accepted_from' => $page);
         }
         if (is_array($parent_offer_id) && count($parent_offer_id) > 0) {
             $args['smart_offers']['parent_offer_id'] = $parent_offer_id;
         } elseif (!is_array($parent_offer_id) && $parent_offer_id != '') {
             $args['smart_offers']['parent_offer_id'] = $parent_offer_id;
         }
         if (!empty($action_on_accept['add_to_cart']) && $action_on_accept['add_to_cart'] == 'yes') {
             $sa_smart_offers->global_wc()->cart->add_to_cart($parent_id, $quantity, $variation_id, $variation, $args);
         }
         $action_on_accept = get_post_meta($post_id, 'so_actions_on_accept', true);
         if (isset($action_on_accept['sa_apply_coupon']) && !empty($action_on_accept['sa_apply_coupon'])) {
             $coupons = explode(",", $action_on_accept['sa_apply_coupon']);
             if (is_array($coupons) && count($coupons) > 0) {
                 foreach ($coupons as $coupon_title) {
                     $sa_smart_offers->global_wc()->cart->add_discount($coupon_title);
                 }
             }
         }
         if (isset($action_on_accept['sa_redirect_to_url']) && !empty($action_on_accept['sa_redirect_to_url'])) {
             $url = $action_on_accept['sa_redirect_to_url'];
         } elseif (isset($action_on_accept['accepted_offer_ids']) && !empty($action_on_accept['accepted_offer_ids'])) {
             $redirecting_option = explode(",", $action_on_accept['accepted_offer_ids']);
             if (is_array($redirecting_option) && count($redirecting_option) > 0) {
                 foreach ($redirecting_option as $id) {
                     $redirect_to = $id;
                 }
             }
             ob_start();
             if ($redirect_to != "") {
                 $this->force_show_smart_offers($redirect_to);
             }
         } elseif (isset($action_on_accept['buy_now']) && $action_on_accept['buy_now'] == true && class_exists('WC_Buy_Now')) {
             $buy_now = new WC_Buy_Now();
             $buy_now->checkout_redirect();
         } else {
             if ($page == "cart_page") {
                 $url = $sa_smart_offers->global_wc()->cart->get_cart_url();
             } elseif (!empty($source)) {
                 if ($page == "checkout_page" && $source == 'so_post_checkout') {
                     $form_values = SO_Session_Handler::check_session_set_or_not('so_checkout_form_data');
                     if ($form_values) {
                         $sa_so_form_checkout = SO_Session_Handler::so_get_session_value('so_checkout_form_data');
                     } else {
                         $sa_so_form_checkout = null;
                     }
                     if (!empty($sa_so_form_checkout)) {
                         $_POST = $sa_so_form_checkout;
                     }
                     if (wc_get_page_id('terms') > 0) {
                         $_POST['terms'] = 'yes';
                     }
                     if ($sa_smart_offers->is_wc_gte_21()) {
                         wc_clear_notices();
                     } else {
                         $sa_smart_offers->global_wc()->clear_messages();
                     }
                     $woocommerce_checkout = $sa_smart_offers->global_wc()->checkout();
                     $woocommerce_checkout->process_checkout();
                 } else {
                     if ($page == "checkout_page" && $source == 'so_pre_checkout') {
                         $url = $sa_smart_offers->global_wc()->cart->get_checkout_url();
                     }
                 }
             } else {
                 $url = $sa_smart_offers->global_wc()->cart->get_checkout_url();
             }
         }
         if (empty($url)) {
             $url = wp_get_referer() ? wp_get_referer() : $sa_smart_offers->global_wc()->cart->get_cart_url();
         }
         if (filter_var($url, FILTER_VALIDATE_URL) !== FALSE) {
             ob_clean();
             wp_redirect($url);
             exit;
         }
     }
 }
Esempio n. 18
0
 /**
  * Test cart fee
  *
  * @since 2.3
  */
 public function test_cart_fee()
 {
     // Create product
     $product = \WC_Helper_Product::create_simple_product();
     update_post_meta($product->id, '_price', '10');
     update_post_meta($product->id, '_regular_price', '10');
     // We need this to have the calculate_totals() method calculate totals
     if (!defined('WOOCOMMERCE_CHECKOUT')) {
         define('WOOCOMMERCE_CHECKOUT', true);
     }
     // Add fee
     \WC_Helper_Fee::add_cart_fee();
     // Add product to cart
     WC()->cart->add_to_cart($product->id, 1);
     // Test if the cart total amount is equal 20
     $this->assertEquals(20, WC()->cart->total);
     // Clearing WC notices
     wc_clear_notices();
     // Clean up the cart
     WC()->cart->empty_cart();
     // Remove fee
     \WC_Helper_Fee::remove_cart_fee();
     // Delete product
     \WC_Helper_Product::delete_product($product->id);
 }
 /**
  * Redirect to PayPal from the product page EC button
  * @param $url
  * @return string
  */
 function add_to_cart_redirect($url)
 {
     if (isset($_REQUEST['express_checkout']) || isset($_REQUEST['express_checkout_x'])) {
         wc_clear_notices();
         $url = esc_url_raw(add_query_arg('pp_action', 'expresscheckout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/'))));
     }
     return $url;
 }
Esempio n. 20
0
 /**
  * Filters cart product
  *
  * @access public
  * @param int $ID
  * @param array $data
  * @return bool
  */
 public static function filterProduct($ID, $data)
 {
     wc_clear_notices();
     $product = $data['product_id'];
     if (!empty($data['variation_id'])) {
         $product = $data['variation_id'];
     }
     $object = wc_get_product($product);
     $cart = self::getCart();
     $quantity = 0;
     foreach ($cart as $products) {
         foreach ($products as $key => $product) {
             if ($key == $ID) {
                 $quantity = $product['quantity'];
                 break;
             }
         }
     }
     if ($object->is_sold_individually() && $quantity > 0) {
         return false;
     }
     if ($object->managing_stock() && !$object->has_enough_stock($quantity + $data['quantity'])) {
         return false;
     }
     return true;
 }
Esempio n. 21
0
 /**
  * Action to perform on accept/skip offer
  */
 function so_process_offer_action()
 {
     global $current_user, $sa_smart_offers;
     $so_offer = new SO_Offer();
     $so_offers = new SO_Offers();
     if (isset($_GET['so_action']) && ($_GET['so_action'] == "accept" || $_GET['so_action'] == "skip")) {
         $current_offer_id = $_GET['so_offer_id'];
         $source = !empty($_GET['source']) ? $_GET['source'] : null;
         list($where, $where_url) = $so_offers->get_page_details();
         $page = $where . '_page';
         list($accepted_session_variable, $accepted_ids_in_session) = $so_offers->get_accepted_offer_ids_from_session();
         list($skipped_session_variable, $skipped_ids_in_session) = $so_offers->get_skipped_offer_ids_from_session();
         $skip_offer_id_variable = $where == "any" ? str_replace(array('/', '-', '&', '=', ':'), '', $where_url) . '_skip_offer_id' : $where . '_skip_offer_id';
         list($offer_id_on_skipping, $skipped_offer_id_variable) = $so_offers->get_offer_id_on_skipping($skip_offer_id_variable);
         $parent_offer_id_variable = $where == "any" ? str_replace(array('/', '-', '&', '=', ':'), '', $where_url) . '_parent_offer_id' : $where . '_parent_offer_id';
         $check_parent_offer_id_set_or_not = SO_Session_Handler::check_session_set_or_not($parent_offer_id_variable);
         if (!$check_parent_offer_id_set_or_not) {
             SO_Session_Handler::so_set_session_variables($parent_offer_id_variable, $current_offer_id);
         }
         if ($_GET['so_action'] == "accept") {
             $variation_data = isset($_POST['variation_id']) || isset($_POST['quantity']) ? $_POST : array();
             $parent_offer_id = '';
             if ($offer_id_on_skipping != '') {
                 $check_parent_offer_id = SO_Session_Handler::check_session_set_or_not($parent_offer_id_variable);
                 $parent_offer_id = $check_parent_offer_id ? SO_Session_Handler::so_get_session_value($parent_offer_id_variable) : '';
             }
             SO_Session_Handler::so_delete_session($parent_offer_id_variable);
             SO_Session_Handler::so_delete_session($skip_offer_id_variable);
             SO_Session_Handler::so_set_session_variables('sa_smart_offers_accepted_offer_ids', $current_offer_id);
             // Update stats
             $so_offer->update_accept_skip_count($current_offer_id, 'accepted');
             // validate offer before add to cart.
             $offer_ids = array($current_offer_id);
             $is_valid = $this->is_offer_valid($page, $offer_ids);
             if (!empty($is_valid) && is_array($is_valid)) {
                 // Adds to cart
                 $so_offer->action_on_accept_offer($current_offer_id, $page, $parent_offer_id, $variation_data);
             } else {
                 // display notice
                 $sa_smart_offers->wc_add_notice(__('This is not valid offer for you.', SA_Smart_Offers::$text_domain), 'error');
             }
         } elseif ($_GET['so_action'] == "skip") {
             $so_offer->update_accept_skip_count($current_offer_id, 'skipped');
             // Update if this offer needs to be skipped permanently for this user
             $skip_permanently = get_post_meta($current_offer_id, 'sa_smart_offer_if_denied_skip_permanently', true);
             if (!empty($skip_permanently) && $skip_permanently == true && $current_user->ID != 0) {
                 $customer_skipped_offers = $this->get_skipped_offers($current_offer_id);
                 $customer_skipped_offers = array_unique($customer_skipped_offers);
                 update_user_meta($current_user->ID, 'customer_skipped_offers', $customer_skipped_offers);
             }
             // To store skipped offers in session even if they are updated in DB
             SO_Session_Handler::so_set_session_variables('sa_smart_offers_skipped_offer_ids', $current_offer_id);
             SO_Session_Handler::so_delete_session($skip_offer_id_variable);
             $redirecting_option = get_post_meta($current_offer_id, 'sa_smart_offer_if_denied', true);
             $redirect_to = get_post_meta($current_offer_id, 'url', true);
             if (strpos($where_url, 'so_action=skip')) {
                 $where_url = esc_url(remove_query_arg(array('so_action', 'so_offer_id', 'source'), $where_url));
             }
             ob_clean();
             if (empty($redirecting_option)) {
                 wp_safe_redirect($where_url);
             } elseif (!empty($source)) {
                 if ($page == "checkout_page" && $source == 'so_post_checkout') {
                     $form_values = SO_Session_Handler::check_session_set_or_not('so_checkout_form_data');
                     if ($form_values) {
                         $sa_so_form_checkout = SO_Session_Handler::so_get_session_value('so_checkout_form_data');
                     } else {
                         $sa_so_form_checkout = null;
                     }
                     if (!empty($sa_so_form_checkout)) {
                         $_POST = $sa_so_form_checkout;
                     }
                     if (wc_get_page_id('terms') > 0) {
                         $_POST['terms'] = 'yes';
                     }
                     if ($sa_smart_offers->is_wc_gte_21()) {
                         wc_clear_notices();
                     } else {
                         $sa_smart_offers->global_wc()->clear_messages();
                     }
                     $woocommerce_checkout = $sa_smart_offers->global_wc()->checkout();
                     $woocommerce_checkout->process_checkout();
                 } elseif ($page == "checkout_page" && $source == 'so_pre_checkout') {
                     wp_safe_redirect($where_url);
                 }
             } else {
                 if ($redirecting_option == 'order_page') {
                     wp_safe_redirect($where_url);
                 } elseif ($redirect_to != "") {
                     if ($redirecting_option == "offer_page") {
                         $so_offer->force_show_smart_offers($redirect_to);
                     } elseif ($redirecting_option == "url") {
                         if (!preg_match("~^(?:ht)tps?://~i", $redirect_to)) {
                             $return_url = @$_SERVER["HTTPS"] == "on" ? "https://" : "http://";
                             $return_url = "http://" . $redirect_to;
                         } else {
                             $return_url = $redirect_to;
                         }
                         wp_redirect($return_url);
                     } elseif ($redirecting_option == "particular_page") {
                         wp_safe_redirect(get_permalink($redirect_to));
                     }
                 }
             }
             exit;
         }
     }
 }
Esempio n. 22
0
function wcpgsk_clear_messages()
{
    if (function_exists('WC') && function_exists('wc_clear_notices')) {
        wc_clear_notices();
    } else {
        global $woocommerce;
        $woocommerce->clear_messages();
    }
}
Esempio n. 23
0
 /**
  * @deprecated 2.1.0
  */
 public function clear_messages()
 {
     _deprecated_function('Woocommerce->clear_messages', '2.1', 'wc_clear_notices');
     wc_clear_notices();
 }
 /**
  * Klarna Checkout coupons AJAX callback.
  *
  * @since  2.0
  **/
 function klarna_checkout_remove_coupon_callback()
 {
     if (!wp_verify_nonce($_REQUEST['nonce'], 'klarna_checkout_nonce')) {
         exit('Nonce can not be verified.');
     }
     global $woocommerce;
     $data = array();
     // Removing coupon
     if (isset($_REQUEST['remove_coupon'])) {
         $remove_coupon = $_REQUEST['remove_coupon'];
         $woocommerce->cart->remove_coupon($remove_coupon);
         $applied_coupons = $woocommerce->cart->applied_coupons;
         $woocommerce->session->set('applied_coupons', $applied_coupons);
         $woocommerce->cart->calculate_totals();
         wc_clear_notices();
         // This notice handled by Klarna plugin
         if (!defined('WOOCOMMERCE_CART')) {
             define('WOOCOMMERCE_CART', true);
         }
         $woocommerce->cart->calculate_shipping();
         $woocommerce->cart->calculate_fees();
         $woocommerce->cart->calculate_totals();
         $this->update_or_create_local_order();
         $data['widget_html'] = $this->klarna_checkout_get_kco_widget_html();
         if (WC()->session->get('klarna_checkout')) {
             $this->ajax_update_klarna_order();
         }
     }
     wp_send_json_success($data);
     wp_die();
 }
Esempio n. 25
0
 /**
  * Test percent product discount method.
  *
  * @since 2.3
  */
 public function test_percent_product_discount()
 {
     // Create product
     $product = WC_Helper_Product::create_simple_product();
     update_post_meta($product->id, '_price', '10');
     update_post_meta($product->id, '_regular_price', '10');
     // Create coupon
     $coupon = WC_Helper_Coupon::create_coupon();
     update_post_meta($coupon->get_id(), 'discount_type', 'percent_product');
     update_post_meta($coupon->get_id(), 'coupon_amount', '5');
     // Create a flat rate method
     WC_Helper_Shipping::create_simple_flat_rate();
     // We need this to have the calculate_totals() method calculate totals
     if (!defined('WOOCOMMERCE_CHECKOUT')) {
         define('WOOCOMMERCE_CHECKOUT', true);
     }
     // Add fee
     WC_Helper_Fee::add_cart_fee();
     // Add product to cart
     WC()->cart->add_to_cart($product->id, 1);
     // Add coupon
     WC()->cart->add_discount($coupon->get_code());
     // Set the flat_rate shipping method
     WC()->session->set('chosen_shipping_methods', array('flat_rate'));
     WC()->cart->calculate_totals();
     // Test if the cart total amount is equal 29.5
     $this->assertEquals(29.5, WC()->cart->total);
     // Clearing WC notices
     wc_clear_notices();
     // Clean up the cart
     WC()->cart->empty_cart();
     // Remove coupons
     WC()->cart->remove_coupons();
     // Remove fee
     WC_Helper_Fee::remove_cart_fee();
     // Delete the flat rate method
     WC()->session->set('chosen_shipping_methods', array());
     WC_Helper_Shipping::delete_simple_flat_rate();
     // Delete coupon
     WC_Helper_Coupon::delete_coupon($coupon->get_id());
     // Delete product
     WC_Helper_Product::delete_product($product->id);
 }
/**
 * Prints messages and errors which are stored in the session, then clears them.
 *
 * @since 2.1
 */
function wc_print_notices()
{
    if (!did_action('woocommerce_init')) {
        _doing_it_wrong(__FUNCTION__, __('This function should not be called before woocommerce_init.', 'woocommerce'), '2.3');
        return;
    }
    $all_notices = WC()->session->get('wc_notices', array());
    $notice_types = apply_filters('woocommerce_notice_types', array('error', 'success', 'notice'));
    foreach ($notice_types as $notice_type) {
        if (wc_notice_count($notice_type) > 0) {
            wc_get_template("notices/{$notice_type}.php", array('messages' => array_filter($all_notices[$notice_type])));
        }
    }
    wc_clear_notices();
}
 /**
  * For a smoother sign up process, tell WooCommerce to redirect the shopper immediately to
  * the checkout page after she clicks the "Sign Up Now" button
  *
  * @param string $url The cart redirect $url WooCommerce determined.
  * @since 1.0
  */
 public static function add_to_cart_redirect($url)
 {
     global $woocommerce;
     // If product is of the subscription type
     if (is_numeric($_REQUEST['add-to-cart']) && WC_Subscriptions_Product::is_subscription((int) $_REQUEST['add-to-cart'])) {
         // Remove default cart message
         if (function_exists('wc_clear_notices')) {
             wc_clear_notices();
         } else {
             // WC < 2.1
             $woocommerce->clear_messages();
         }
         // Redirect to checkout
         $url = $woocommerce->cart->get_checkout_url();
     }
     return $url;
 }
 /**
  * Redirects directly to the cart the products they need confirmation
  *
  * @param string $url
  */
 public function add_to_cart_redirect($url)
 {
     if (isset($_REQUEST['add-to-cart']) && is_numeric($_REQUEST['add-to-cart']) && wc_booking_requires_confirmation(intval($_REQUEST['add-to-cart']))) {
         // Remove add to cart messages
         wc_clear_notices();
         // Go to checkout
         return WC()->cart->get_cart_url();
     }
     return $url;
 }
Esempio n. 29
0
 /**
  * Test wc_clear_notices().
  *
  * @since 2.2
  */
 function test_wc_clear_notices()
 {
     wc_add_notice('Test Notice');
     wc_clear_notices();
     $this->assertEmpty(WC()->session->get('wc_notices'));
 }
 /**
  *  PayPal Express Checkout
  *
  *  Main action function that handles PPE actions:
  *  1. 'expresscheckout' - Initiates the Express Checkout process; called by the checkout button.
  *  2. 'revieworder' - Customer has reviewed the order. Saves shipping info to order.
  *  3. 'payaction' - Customer has pressed "Place Order" on the review page.
  */
 function paypal_express_checkout($posted = null)
 {
     if (!empty($posted) || isset($_GET['pp_action']) && $_GET['pp_action'] == 'expresscheckout') {
         if (sizeof(WC()->cart->get_cart()) > 0) {
             // The customer has initiated the Express Checkout process with the button on the cart page
             if (!defined('WOOCOMMERCE_CHECKOUT')) {
                 define('WOOCOMMERCE_CHECKOUT', true);
             }
             $this->add_log('Start Express Checkout');
             /**
              * Check if the EC button used was the PayPal Credit button.
              * This $usePayPalCredit flag will be used to adjust the SEC request accordingly.
              */
             if (isset($_GET['use_paypal_credit']) && 'true' == $_GET['use_paypal_credit']) {
                 $usePayPalCredit = true;
             } else {
                 $usePayPalCredit = false;
             }
             WC()->cart->calculate_totals();
             //$paymentAmount    = WC()->cart->get_total();
             $paymentAmount = number_format(WC()->cart->total, 2, '.', '');
             //Check if review order page is exist, otherwise re-create it on the fly
             $review_order_page_url = get_permalink(wc_get_page_id('review_order'));
             if (!$review_order_page_url) {
                 $this->add_log(__('Review Order Page not found, re-create it. ', 'paypal-for-woocommerce'));
                 include_once WC()->plugin_path() . '/includes/admin/wc-admin-functions.php';
                 $page_id = wc_create_page(esc_sql(_x('review-order', 'page_slug', 'woocommerce')), 'woocommerce_review_order_page_id', __('Checkout &rarr; Review Order', 'paypal-for-woocommerce'), '[woocommerce_review_order]', wc_get_page_id('checkout'));
                 $review_order_page_url = get_permalink($page_id);
             }
             $returnURL = urlencode(add_query_arg('pp_action', 'revieworder', $review_order_page_url));
             $cancelURL = urlencode(WC()->cart->get_cart_url());
             $resArray = $this->CallSetExpressCheckout($paymentAmount, $returnURL, $cancelURL, $usePayPalCredit, $posted);
             $ack = strtoupper($resArray["ACK"]);
             /**
              * I've replaced the original redirect URL's here with
              * what the PayPal class library returns so that options like
              * "skip details" will work correctly with PayPal's review pages.
              */
             if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
                 $this->add_log('Redirecting to PayPal');
                 if (is_ajax()) {
                     $result = array('redirect' => $resArray['REDIRECTURL'], 'result' => 'success');
                     echo '<!--WC_START-->' . json_encode($result) . '<!--WC_END-->';
                     exit;
                 } else {
                     //$this->RedirectToPayPal( $resArray["TOKEN"] );
                     wp_redirect($resArray['REDIRECTURL']);
                     exit;
                 }
             } else {
                 // Display a user friendly Error on the page and log details
                 $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
                 $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
                 $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
                 $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
                 $this->add_log(__('SetExpressCheckout API call failed. ', 'paypal-for-woocommerce'));
                 $this->add_log(__('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg);
                 $this->add_log(__('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg);
                 $this->add_log(__('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode);
                 $this->add_log(__('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode);
                 // Notice admin if has any issue from PayPal
                 $message = '';
                 if ($this->error_email_notify) {
                     $admin_email = get_option("admin_email");
                     $message .= __("SetExpressCheckout API call failed.", "paypal-for-woocommerce") . "\n\n";
                     $message .= __('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode . "\n";
                     $message .= __('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode . "\n";
                     $message .= __('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg . "\n";
                     $message .= __('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg . "\n";
                     wp_mail($admin_email, "PayPal Express Checkout Error Notification", $message);
                 }
                 // Generate error message based on Error Display Type setting
                 if ($this->error_display_type == 'detailed') {
                     $sec_error_notice = $ErrorCode . ' - ' . $ErrorLongMsg;
                     wc_add_notice(sprintf(__($sec_error_notice, 'paypal-for-woocommerce')), 'error');
                 } else {
                     wc_add_notice(sprintf(__('There was a problem paying with PayPal.  Please try another method.', 'paypal-for-woocommerce')), 'error');
                 }
                 if (!is_ajax()) {
                     wp_redirect(get_permalink(wc_get_page_id('cart')));
                     exit;
                 } else {
                     return;
                 }
             }
         }
     } elseif (isset($_GET['pp_action']) && $_GET['pp_action'] == 'revieworder') {
         wc_clear_notices();
         // The customer has logged into PayPal and approved order.
         // Retrieve the shipping details and present the order for completion.
         if (!defined('WOOCOMMERCE_CHECKOUT')) {
             define('WOOCOMMERCE_CHECKOUT', true);
         }
         $this->add_log('Start Review Order');
         if (isset($_GET['token'])) {
             $token = $_GET['token'];
             $this->set_session('TOKEN', $token);
         }
         if (isset($_GET['PayerID'])) {
             $payerID = $_GET['PayerID'];
             $this->set_session('PayerID', $payerID);
         }
         $this->add_log("...Token:" . $this->get_session('TOKEN'));
         $this->add_log("...PayerID: " . $this->get_session('PayerID'));
         $result = $this->CallGetShippingDetails($this->get_session('TOKEN'));
         if (!empty($result)) {
             $this->set_session('RESULT', serialize($result));
             if (isset($result['SHIPTOCOUNTRYCODE'])) {
                 /**
                  * Check if shiptocountry is in the allowed countries list
                  */
                 if (!array_key_exists($result['SHIPTOCOUNTRYCODE'], WC()->countries->get_allowed_countries())) {
                     wc_add_notice(sprintf(__('We do not sell in your country, please try again with another address.', 'paypal-for-woocommerce')), 'error');
                     wp_redirect(get_permalink(wc_get_page_id('cart')));
                     exit;
                 }
                 WC()->customer->set_shipping_country($result['SHIPTOCOUNTRYCODE']);
             }
             if (isset($result['SHIPTONAME'])) {
                 WC()->customer->shiptoname = $result['SHIPTONAME'];
             }
             if (isset($result['SHIPTOSTREET'])) {
                 WC()->customer->set_address($result['SHIPTOSTREET']);
             }
             if (isset($result['SHIPTOCITY'])) {
                 WC()->customer->set_city($result['SHIPTOCITY']);
             }
             if (isset($result['SHIPTOCOUNTRYCODE'])) {
                 WC()->customer->set_country($result['SHIPTOCOUNTRYCODE']);
             }
             if (isset($result['SHIPTOSTATE'])) {
                 WC()->customer->set_state($this->get_state_code($result['SHIPTOCOUNTRYCODE'], $result['SHIPTOSTATE']));
             }
             if (isset($result['SHIPTOZIP'])) {
                 WC()->customer->set_postcode($result['SHIPTOZIP']);
             }
             if (isset($result['SHIPTOSTATE'])) {
                 WC()->customer->set_shipping_state($this->get_state_code($result['SHIPTOCOUNTRYCODE'], $result['SHIPTOSTATE']));
             }
             if (isset($result['SHIPTOZIP'])) {
                 WC()->customer->set_shipping_postcode($result['SHIPTOZIP']);
             }
             /**
              * Save GECD data in sessions for use in DECP
              */
             $this->set_session('firstname', isset($result['FIRSTNAME']) ? $result['FIRSTNAME'] : '');
             $this->set_session('lastname', isset($result['LASTNAME']) ? $result['LASTNAME'] : '');
             $this->set_session('shiptoname', isset($result['SHIPTONAME']) ? $result['SHIPTONAME'] : '');
             $this->set_session('shiptostreet', isset($result['SHIPTOSTREET']) ? $result['SHIPTOSTREET'] : '');
             $this->set_session('shiptostreet2', isset($result['SHIPTOSTREET2']) ? $result['SHIPTOSTREET2'] : '');
             $this->set_session('shiptocity', isset($result['SHIPTOCITY']) ? $result['SHIPTOCITY'] : '');
             $this->set_session('shiptocountrycode', isset($result['SHIPTOCOUNTRYCODE']) ? $result['SHIPTOCOUNTRYCODE'] : '');
             $this->set_session('shiptostate', isset($result['SHIPTOSTATE']) ? $result['SHIPTOSTATE'] : '');
             $this->set_session('shiptozip', isset($result['SHIPTOZIP']) ? $result['SHIPTOZIP'] : '');
             $this->set_session('payeremail', isset($result['EMAIL']) ? $result['EMAIL'] : '');
             $this->set_session('giftmessage', isset($result['GIFTMESSAGE']) ? $result['GIFTMESSAGE'] : '');
             $this->set_session('giftreceiptenable', isset($result['GIFTRECEIPTENABLE']) ? $result['GIFTRECEIPTENABLE'] : '');
             $this->set_session('giftwrapname', isset($result['GIFTWRAPNAME']) ? $result['GIFTWRAPNAME'] : '');
             $this->set_session('giftwrapamount', isset($result['GIFTWRAPAMOUNT']) ? $result['GIFTWRAPAMOUNT'] : '');
             $this->set_session('customer_notes', isset($result['PAYMENTREQUEST_0_NOTETEXT']) ? $result['PAYMENTREQUEST_0_NOTETEXT'] : '');
             $this->set_session('phonenum', isset($result['PHONENUM']) ? $result['PHONENUM'] : '');
             WC()->cart->calculate_totals();
         } else {
             $this->add_log("...ERROR: GetShippingDetails returned empty result");
         }
         if ($this->skip_final_review == 'yes') {
             $url = add_query_arg(array('wc-api' => 'WC_Gateway_PayPal_Express_AngellEYE', 'pp_action' => 'payaction'), home_url());
             wp_redirect($url);
             exit;
         }
         if (isset($_POST['createaccount'])) {
             if (empty($_POST['username'])) {
                 wc_add_notice(__('Username is required', 'paypal-for-woocommerce'), 'error');
             } elseif (username_exists($_POST['username'])) {
                 wc_add_notice(__('This username is already registered.', 'paypal-for-woocommerce'), 'error');
             } elseif (empty($_POST['email'])) {
                 wc_add_notice(__('Please provide a valid email address.', 'paypal-for-woocommerce'), 'error');
             } elseif (empty($_POST['password']) || empty($_POST['repassword'])) {
                 wc_add_notice(__('Password is required.', 'paypal-for-woocommerce'), 'error');
             } elseif ($_POST['password'] != $_POST['repassword']) {
                 wc_add_notice(__('Passwords do not match.', 'paypal-for-woocommerce'), 'error');
             } elseif (get_user_by('email', $_POST['email']) != false) {
                 wc_add_notice(__('This email address is already registered.', 'paypal-for-woocommerce'), 'error');
             } else {
                 $data = array('user_login' => addslashes($_POST['username']), 'user_email' => addslashes($_POST['email']), 'user_pass' => addslashes($_POST['password']));
                 $userID = wp_insert_user($data);
                 if (!is_wp_error($userID)) {
                     update_user_meta($userID, 'billing_first_name', $result['FIRSTNAME']);
                     update_user_meta($userID, 'billing_last_name', $result['LASTNAME']);
                     update_user_meta($userID, 'billing_address_1', $result['SHIPTOSTREET']);
                     update_user_meta($userID, 'billing_state', $result['SHIPTOSTATE']);
                     update_user_meta($userID, 'billing_email', $result['EMAIL']);
                     /* USER SIGON */
                     $user_login = esc_attr($_POST["username"]);
                     $user_password = esc_attr($_POST["password"]);
                     $user_email = esc_attr($_POST["email"]);
                     $creds = array('user_login' => $user_login, 'user_password' => $user_password, 'remember' => true);
                     $user = wp_signon($creds, false);
                     if (is_wp_error($user)) {
                         wc_add_notice($user->get_error_message(), 'error');
                     } else {
                         wp_set_current_user($user->ID);
                         //Here is where we update the global user variables
                         header("Refresh:0");
                         die;
                     }
                 }
             }
         }
     } elseif (isset($_GET['pp_action']) && $_GET['pp_action'] == 'payaction') {
         if (isset($_POST) || $this->skip_final_review == 'yes') {
             // Update customer shipping and payment method to posted method
             $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
             if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method'])) {
                 foreach ($_POST['shipping_method'] as $i => $value) {
                     $chosen_shipping_methods[$i] = wc_clean($value);
                 }
             }
             WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
             if (WC()->cart->needs_shipping()) {
                 // Validate Shipping Methods
                 $packages = WC()->shipping->get_packages();
                 WC()->checkout()->shipping_methods = WC()->session->get('chosen_shipping_methods');
             }
             $this->add_log('Start Pay Action');
             if (!defined('WOOCOMMERCE_CHECKOUT')) {
                 define('WOOCOMMERCE_CHECKOUT', true);
             }
             WC()->cart->calculate_totals();
             $order_id = WC()->checkout()->create_order();
             /**
              * Update meta data with session data
              */
             // Parse SHIPTONAME to fist and last name
             require_once "lib/NameParser.php";
             $parser = new FullNameParser();
             $split_name = $parser->split_full_name($this->get_session('shiptoname'));
             $shipping_first_name = $split_name['fname'];
             $shipping_last_name = $split_name['lname'];
             $full_name = $split_name['fullname'];
             update_post_meta($order_id, '_payment_method', $this->id);
             update_post_meta($order_id, '_payment_method_title', $this->title);
             if (is_user_logged_in()) {
                 $userLogined = get_current_user();
                 update_post_meta($order_id, '_billing_email', $userLogined->user_email);
             } else {
                 update_post_meta($order_id, '_billing_email', $this->get_session('payeremail'));
             }
             update_post_meta($order_id, '_shipping_first_name', $shipping_first_name);
             update_post_meta($order_id, '_shipping_last_name', $shipping_last_name);
             update_post_meta($order_id, '_shipping_full_name', $full_name);
             update_post_meta($order_id, '_shipping_company', "");
             update_post_meta($order_id, '_billing_phone', $this->get_session('phonenum'));
             update_post_meta($order_id, '_shipping_address_1', $this->get_session('shiptostreet'));
             update_post_meta($order_id, '_shipping_address_2', $this->get_session('shiptostreet2'));
             update_post_meta($order_id, '_shipping_city', $this->get_session('shiptocity'));
             update_post_meta($order_id, '_shipping_postcode', $this->get_session('shiptozip'));
             update_post_meta($order_id, '_shipping_country', $this->get_session('shiptocountrycode'));
             update_post_meta($order_id, '_shipping_state', $this->get_state_code($this->get_session('shiptocountrycode'), $this->get_session('shiptostate')));
             update_post_meta($order_id, '_customer_user', get_current_user_id());
             $this->add_log('...Order ID: ' . $order_id);
             $order = new WC_Order($order_id);
             do_action('woocommerce_ppe_do_payaction', $order);
             $this->add_log('...Order Total: ' . $order->order_total);
             $this->add_log('...Cart Total: ' . WC()->cart->get_total());
             $this->add_log("...Token:" . $this->get_session('TOKEN'));
             $result = $this->ConfirmPayment($order->order_total);
             // Set Customer Name
             if (!get_current_user_id()) {
                 update_post_meta($order_id, '_billing_first_name', $this->get_session('firstname'));
                 update_post_meta($order_id, '_billing_last_name', $this->get_session('lastname'));
             }
             /**
              * Customer Notes
              */
             if ($this->get_session('customer_notes') != '') {
                 $order->add_order_note(__('Customer Notes: ', 'paypal-for-woocommerce') . $this->get_session('customer_notes'));
             }
             if ($result['ACK'] == 'Success' || $result['ACK'] == 'SuccessWithWarning') {
                 $this->add_log('Payment confirmed with PayPal successfully');
                 $result = apply_filters('woocommerce_payment_successful_result', $result);
                 /**
                  * Gift Wrap Notes
                  */
                 if ($this->get_session('giftwrapamount') != '') {
                     $giftwrap_note = __('Gift Wrap Added', 'paypal-for-woocommerce');
                     $giftwrap_note .= $this->get_session('giftwrapname') != '' ? ' - ' . $this->get_session('giftwrapname') : '';
                     $giftwrap_note .= $this->get_session('giftmessage') != '' ? '<br />Message: ' . $this->get_session('giftmessage') : '';
                     $giftwrap_note .= '<br />' . __('Use Gift Receipt?: ', 'paypal-for-woocommerce');
                     $giftwrap_note .= strtolower($this->get_session('giftreceiptenable')) == 'true' ? 'Yes' : 'No';
                     //$giftwrap_note .= '<br />Fee: ' . woocommerce_price(number_format($this->get_session('giftwrapamount'),2));
                     $order->add_order_note($giftwrap_note);
                 }
                 $order->add_order_note(__('PayPal Express payment completed', 'paypal-for-woocommerce') . ' ( Response Code: ' . $result['ACK'] . ", " . ' TransactionID: ' . $result['PAYMENTINFO_0_TRANSACTIONID'] . ' )');
                 $REVIEW_RESULT = unserialize($this->get_session('RESULT'));
                 $payerstatus_note = __('Payer Status: ', 'paypal-for-woocommerce');
                 $payerstatus_note .= ucfirst($REVIEW_RESULT['PAYERSTATUS']);
                 $order->add_order_note($payerstatus_note);
                 $addressstatus_note = __('Address Status: ', 'paypal-for-woocommerce');
                 $addressstatus_note .= ucfirst($REVIEW_RESULT['ADDRESSSTATUS']);
                 $order->add_order_note($addressstatus_note);
                 $order->payment_complete($result['PAYMENTINFO_0_TRANSACTIONID']);
                 //add hook
                 do_action('woocommerce_checkout_order_processed', $order_id);
                 // Empty the Cart
                 WC()->cart->empty_cart();
                 wp_redirect($this->get_return_url($order));
                 exit;
             } else {
                 $this->add_log('...Error confirming order ' . $order_id . ' with PayPal');
                 $this->add_log('...response:' . print_r($result, true));
                 // Display a user friendly Error on the page and log details
                 $ErrorCode = urldecode($result["L_ERRORCODE0"]);
                 $ErrorShortMsg = urldecode($result["L_SHORTMESSAGE0"]);
                 $ErrorLongMsg = urldecode($result["L_LONGMESSAGE0"]);
                 $ErrorSeverityCode = urldecode($result["L_SEVERITYCODE0"]);
                 $this->add_log('SetExpressCheckout API call failed. ');
                 $this->add_log('Detailed Error Message: ' . $ErrorLongMsg);
                 $this->add_log('Short Error Message: ' . $ErrorShortMsg);
                 $this->add_log('Error Code: ' . $ErrorCode);
                 $this->add_log('Error Severity Code: ' . $ErrorSeverityCode);
                 if ($ErrorCode == '10486') {
                     $this->RedirectToPayPal($this->get_session('TOKEN'));
                 }
                 // Notice admin if has any issue from PayPal
                 $message = '';
                 if ($this->error_email_notify) {
                     $admin_email = get_option("admin_email");
                     $message .= __("DoExpressCheckoutPayment API call failed.", "paypal-for-woocommerce") . "\n\n";
                     $message .= __('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode . "\n";
                     $message .= __('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode . "\n";
                     $message .= __('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg . "\n";
                     $message .= __('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg . "\n";
                     wp_mail($admin_email, "PayPal Express Checkout Error Notification", $message);
                 }
                 // Generate error message based on Error Display Type setting
                 if ($this->error_display_type == 'detailed') {
                     $sec_error_notice = $ErrorCode . ' - ' . $ErrorLongMsg;
                     wc_add_notice(sprintf(__($sec_error_notice, 'paypal-for-woocommerce')), 'error');
                 } else {
                     wc_add_notice(sprintf(__('There was a problem paying with PayPal.  Please try another method.', 'paypal-for-woocommerce')), 'error');
                 }
                 wp_redirect(get_permalink(wc_get_page_id('cart')));
                 exit;
             }
         }
     }
 }