function install_woocommerce_catalog_restrictions() { global $woocommerce, $wc_catalog_restrictions, $wpdb; if (!WC_Catalog_Visibility_Compatibility::is_wc_version_gte_2_1()) { include_once $woocommerce->plugin_path() . '/admin/woocommerce-admin-install.php'; } //Clean up old rules. $wc_term_meta_table = $wpdb->prefix . 'woocommerce_termmeta'; $wpdb->query("DELETE FROM {$wc_term_meta_table} WHERE (meta_key = '_wc_restrictions' OR meta_key = '_wc_restrictions_allowed') AND (meta_value = '');"); $wpdb->query("DELETE FROM {$wc_term_meta_table} WHERE (meta_key = '_wc_restrictions_location' OR meta_key = '_wc_restrictions_locations') AND (meta_value = '');"); //Clean up the transients $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_twccr%'"); $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_twccr%'"); if (!get_option('woocommerce_choose_location_page_id')) { if (!WC_Catalog_Visibility_Compatibility::is_wc_version_gte_2_1()) { wc_create_page(esc_sql(_x('choose-location', 'page_slug', 'wc_catalog_restrictions')), 'woocommerce_choose_location_page_id', __('Your Location', 'wc_catalog_restrictions'), '[location_picker /]'); } else { woocommerce_create_page(esc_sql(_x('choose-location', 'page_slug', 'wc_catalog_restrictions')), 'woocommerce_choose_location_page_id', __('Your Location', 'wc_catalog_restrictions'), '[location_picker /]'); } } update_option("woocommerce_catalog_restrictions_db_version", $wc_catalog_restrictions->version); }
/** * Create pages that the plugin relies on, storing page id's in variables. */ public static function create_pages() { include_once dirname(__FILE__) . '/admin/wc-admin-functions.php'; $pages = apply_filters('woocommerce_create_pages', array('shop' => array('name' => _x('shop', 'Page slug', 'woocommerce'), 'title' => _x('Shop', 'Page title', 'woocommerce'), 'content' => ''), 'cart' => array('name' => _x('cart', 'Page slug', 'woocommerce'), 'title' => _x('Cart', 'Page title', 'woocommerce'), 'content' => '[' . apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart') . ']'), 'checkout' => array('name' => _x('checkout', 'Page slug', 'woocommerce'), 'title' => _x('Checkout', 'Page title', 'woocommerce'), 'content' => '[' . apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout') . ']'), 'myaccount' => array('name' => _x('my-account', 'Page slug', 'woocommerce'), 'title' => _x('My account', 'Page title', 'woocommerce'), 'content' => '[' . apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account') . ']'))); foreach ($pages as $key => $page) { wc_create_page(esc_sql($page['name']), 'woocommerce_' . $key . '_page_id', $page['title'], $page['content'], !empty($page['parent']) ? wc_get_page_id($page['parent']) : ''); } delete_transient('woocommerce_cache_excluded_uris'); }
/** * Create pages that the plugin relies on, storing page id's in variables. * * @access public * @return void */ public static function create_pages() { $pages = apply_filters('woocommerce_create_pages', array('shop' => array('name' => _x('shop', 'Page slug', 'woocommerce'), 'title' => _x('Shop', 'Page title', 'woocommerce'), 'content' => ''), 'cart' => array('name' => _x('cart', 'Page slug', 'woocommerce'), 'title' => _x('Cart', 'Page title', 'woocommerce'), 'content' => '[' . apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart') . ']'), 'checkout' => array('name' => _x('checkout', 'Page slug', 'woocommerce'), 'title' => _x('Checkout', 'Page title', 'woocommerce'), 'content' => '[' . apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout') . ']'), 'myaccount' => array('name' => _x('my-account', 'Page slug', 'woocommerce'), 'title' => _x('My Account', 'Page title', 'woocommerce'), 'content' => '[' . apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account') . ']'))); foreach ($pages as $key => $page) { wc_create_page(esc_sql($page['name']), 'woocommerce_' . $key . '_page_id', $page['title'], $page['content'], !empty($page['parent']) ? wc_get_page_id($page['parent']) : ''); } }
/** * @deprecated */ function woocommerce_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { _deprecated_function('woocommerce_create_page', '2.1', 'wc_create_page'); return wc_create_page($slug, $option, $page_title, $page_content, $post_parent); }
/** * 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 = AngellEYE_Gateway_Paypal::number_format(WC()->cart->total); //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 → 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_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); $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 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"; $message .= __('User IP: ', 'paypal-for-woocommerce') . $this->get_user_ip() . "\n"; $error_email_notify_mes = apply_filters('ae_ppec_error_email_message', $message, $ErrorCode, $ErrorSeverityCode, $ErrorShortMsg, $ErrorLongMsg); $subject = "PayPal Express Checkout Error Notification"; $error_email_notify_subject = apply_filters('ae_ppec_error_email_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('ae_ppec_error_user_display_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') { // 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')); //if empty TOKEN redirect to cart page if (empty(WC()->session->TOKEN)) { $ms = sprintf(__('Sorry, your session has expired. <a href=%s>Return to homepage →</a>', 'paypal-for-woocommerce'), '"' . home_url() . '"'); $ec_confirm_message = apply_filters('angelleye_ec_confirm_message', $ms); wc_add_notice($ec_confirm_message, "error"); wp_redirect(get_permalink(wc_get_page_id('cart'))); } else { $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['FIRSTNAME'])) { WC()->customer->firstname = $result['FIRSTNAME']; } if (isset($result['LASTNAME'])) { WC()->customer->lastname = $result['LASTNAME']; } if (isset($result['SHIPTONAME'])) { WC()->customer->shiptoname = $result['SHIPTONAME']; } if (isset($result['SHIPTOSTREET'])) { WC()->customer->set_address($result['SHIPTOSTREET']); } if (isset($result['SHIPTOSTREET2'])) { WC()->customer->set_address_2($result['SHIPTOSTREET2']); } 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" || apply_filters('woocommerce_enable_guest_checkout', get_option('woocommerce_enable_guest_checkout')) == "yes" || is_user_logged_in()) || is_user_logged_in() && isset(WC()->session->checkout_form)) { //check terms enable $checkout_form_data = maybe_unserialize(WC()->session->checkout_form); if (!(wc_get_page_id('terms') > 0 && apply_filters('woocommerce_checkout_show_terms', true) && empty($checkout_form_data['terms']))) { $url = add_query_arg(array('pp_action' => 'payaction')); 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']) || !is_email($_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 { $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($new_customer->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 PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/lib/NameParser.php'; $parser = new FullNameParser(); if (isset($result['SHIPTONAME']) && !empty($result['SHIPTONAME'])) { $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', isset($shipping_first_name) ? $shipping_first_name : ''); update_user_meta($this->customer_id, 'shipping_last_name', isset($shipping_last_name) ? $shipping_first_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', $result['FIRSTNAME']); update_user_meta($this->customer_id, 'billing_last_name', $result['LASTNAME']); 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'] : ''); } } //reload the page wp_redirect(add_query_arg(array('pp_action' => 'revieworder'))); exit; } } } } elseif (isset($_GET['pp_action']) && $_GET['pp_action'] == 'payaction') { if (isset($_POST) || ($this->skip_final_review == 'yes' && (get_option('woocommerce_enable_guest_checkout') === "yes" || apply_filters('woocommerce_enable_guest_checkout', get_option('woocommerce_enable_guest_checkout')) == "yes" || is_user_logged_in()) || is_user_logged_in() && isset(WC()->session->checkout_form))) { $result = unserialize(WC()->session->RESULT); /* create account start */ if (isset($_POST['createaccount']) && !empty($_POST['createaccount'])) { $this->customer_id = apply_filters('woocommerce_checkout_customer_id', get_current_user_id()); $create_user_email = $_POST['email']; $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 have any issue, redirect to review-order page $create_acc_error = false; if (empty($_POST['email']) || !is_email($_POST['email'])) { wc_add_notice(__('Please provide a valid email address.', 'paypal-for-woocommerce'), 'error'); } elseif (get_user_by('email', $create_user_email) != false) { wc_add_notice(__('This email address is already registered.', 'paypal-for-woocommerce'), 'error'); $create_acc_error = true; } elseif (empty($_POST['create_act'])) { wc_add_notice(__('Password is required.', 'paypal-for-woocommerce'), 'error'); $create_acc_error = true; } else { $username = !empty($create_user_name) ? $create_user_name : ''; $password = !empty($_POST['create_act']) ? $_POST['create_act'] : ''; $email = $create_user_email; try { //try to create user $new_customer = wc_create_new_customer(sanitize_email($email), wc_clean($username), $password); if (is_wp_error($new_customer)) { wc_add_notice($new_customer->get_error_message(), 'error'); $create_acc_error = true; } if (apply_filters('paypal-for-woocommerce_registration_auth_new_customer', true, $new_customer)) { wc_set_customer_auth_cookie($new_customer); } //Log user in $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'); $create_acc_error = true; } 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); $this->customer_id = $user->ID; } } catch (Exception $e) { wc_add_notice('<strong>' . __('Error', 'paypal-for-woocommerce') . ':</strong> ' . $e->getMessage(), 'error'); $create_acc_error = true; } } if ($create_acc_error) { wp_redirect(add_query_arg(array('pp_action' => 'revieworder'))); exit; } } // 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(); if (sizeof(WC()->cart->get_cart()) == 0 || empty(WC()->session->TOKEN)) { $ms = sprintf(__('Sorry, your session has expired. <a href=%s>Return to homepage →</a>', 'paypal-for-woocommerce'), '"' . home_url() . '"'); $ec_confirm_message = apply_filters('angelleye_ec_confirm_message', $ms); wc_add_notice($ec_confirm_message, "error"); wp_redirect(get_permalink(wc_get_page_id('cart'))); exit; } $paid_order_id = $this->angelleye_prevent_duplicate_payment_request(WC()->session->TOKEN); if ($paid_order_id) { $ms = sprintf(__('Sorry, A successful transaction has already been completed for this token. <a href=%s>Return to homepage →</a>', 'paypal-for-woocommerce'), '"' . home_url() . '"'); $ec_confirm_message = apply_filters('angelleye_ec_confirm_message', $ms); wc_add_notice($ec_confirm_message, "error"); wp_redirect(get_permalink(wc_get_page_id('cart'))); exit; } $order_id = WC()->checkout()->create_order(); do_action('woocommerce_checkout_order_processed', $order_id, array()); /** * Update meta data with session data */ // Parse SHIPTONAME to fist and last name require_once PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/lib/NameParser.php'; $parser = new FullNameParser(); $shiptoname_from_session = $this->get_session('shiptoname'); if (isset($shiptoname_from_session) && !empty($shiptoname_from_session)) { $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']; } else { if (!isset($shipping_first_name)) { $shipping_first_name = ''; } if (!isset($shipping_last_name)) { $shipping_last_name = ''; } } $this->set_session('firstname', isset($result['FIRSTNAME']) ? $result['FIRSTNAME'] : $shipping_first_name); $this->set_session('lastname', isset($result['LASTNAME']) ? $result['LASTNAME'] : $shipping_last_name); update_post_meta($order_id, '_payment_method', $this->id); update_post_meta($order_id, '_payment_method_title', $this->title); $checkout_form_data = maybe_unserialize($this->get_session('checkout_form')); 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 { if (isset($checkout_form_data['billing_email'])) { update_post_meta($order_id, '_billing_email', $checkout_form_data['billing_email']); } else { update_post_meta($order_id, '_billing_email', $this->get_session('payeremail')); } } //save PayPal email update_post_meta($order_id, 'paypal_email', $this->get_session('payeremail')); //Set POST data from SESSION $checkout_form_post_data = maybe_unserialize($this->get_session('checkout_form_post_data')); if (isset($checkout_form_post_data) && !empty($checkout_form_post_data)) { $_POST = $checkout_form_post_data; } do_action('woocommerce_checkout_update_user_meta', $this->customer_id, $checkout_form_data); do_action('woocommerce_checkout_update_order_meta', $order_id, $checkout_form_data); 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 (isset($checkout_form_data['ship_to_different_address']) && $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); } } } else { update_post_meta($order_id, '_shipping_first_name', isset($shipping_first_name) ? $shipping_first_name : ''); update_post_meta($order_id, '_shipping_last_name', isset($shipping_last_name) ? $shipping_last_name : ''); update_post_meta($order_id, '_shipping_full_name', isset($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', isset($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') != '') { $customer_notes = $this->get_session('customer_notes'); } else { if (isset($checkout_form_data['order_comments'])) { $customer_notes = $checkout_form_data['order_comments']; } } if (!empty($customer_notes)) { // Update post 37 $checkout_note = array('ID' => $order_id, 'post_excerpt' => $customer_notes); wp_update_post($checkout_note); $checkout_form_data['order_comments'] = ''; unset($checkout_form_data['order_comments']); } if ($result['ACK'] == 'Success' || $result['ACK'] == 'SuccessWithWarning') { $this->add_log('Payment confirmed with PayPal successfully'); $result = apply_filters('woocommerce_payment_successful_result', $result, $order_id); /** * Gift Wrap Notes */ if ($this->get_session('giftwrapamount') != '') { update_post_meta($order_id, 'giftwrapamount', $this->get_session('giftwrapamount')); if ($this->get_session('giftmessage') != '') { update_post_meta($order_id, 'giftmessage', $this->get_session('giftmessage')); } if ($this->get_session('giftwrapname') != '') { update_post_meta($order_id, 'giftwrapname', $this->get_session('giftwrapname')); } if ($this->get_session('giftmessage') != '') { update_post_meta($order_id, 'giftmessage', $this->get_session('giftmessage')); } $giftreceiptenable = strtolower($this->get_session('giftreceiptenable')) == 'true' ? 'true' : 'false'; update_post_meta($order_id, 'giftreceiptenable', $giftreceiptenable); } update_post_meta($order_id, '_express_checkout_token', $this->get_session('TOKEN')); $this->remove_session('TOKEN'); $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'); if (isset($REVIEW_RESULT['ADDRESSSTATUS']) && !empty($REVIEW_RESULT['ADDRESSSTATUS'])) { $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); unset(WC()->session->checkout_form); unset(WC()->session->checkout_form_post_data); // 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('DoExpressCheckoutPayment 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 .= __('User IP: ', 'paypal-for-woocommerce') . $this->get_user_ip() . "\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('ae_ppec_error_email_message', $message, $ErrorCode, $ErrorSeverityCode, $ErrorShortMsg, $ErrorLongMsg); $subject = "PayPal Express Checkout Error Notification"; $error_email_notify_subject = apply_filters('ae_ppec_error_email_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('ae_ppec_error_user_display_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; } } } }
public static function create_become_a_vendor_page() { $become_a_vendor_page = get_option('yith_wpv_become_a_vendor_page_id'); if ($become_a_vendor_page === false) { /* wc_create_page( $slug, $option, $page_title, $page_content, $post_parent ) */ $page_id = wc_create_page('become-a-vendor', 'yith_wpv_become_a_vendor_page_id', __('Become a vendor', 'yith_wc_product_vendors'), '[yith_wcmv_become_a_vendor]', 0); } }
/** * Run when plugin is activated */ function activate_paypal_for_woocommerce() { // If WooCommerce is not enabled, deactivate plugin. if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))) && !is_plugin_active_for_network('woocommerce/woocommerce.php')) { deactivate_plugins(plugin_basename(__FILE__)); } else { global $woocommerce; // Create review page for Express Checkout wc_create_page(esc_sql(_x('review-order', 'page_slug', 'woocommerce')), 'woocommerce_review_order_page_id', __('Checkout → Review Order', 'paypal-for-woocommerce'), '[woocommerce_review_order]', wc_get_page_id('checkout')); // Log activation in Angell EYE database via web service. $log_url = $_SERVER['HTTP_HOST']; $log_plugin_id = 1; $log_activation_status = 1; wp_remote_request('http://www.angelleye.com/web-services/wordpress/update-plugin-status.php?url=' . $log_url . '&plugin_id=' . $log_plugin_id . '&activation_status=' . $log_activation_status); } }
/** * Creates the unsubscribe page * * @since 1.0.0 * @return void * @author Alberto Ruggiero */ public function ywrr_create_pages() { if (!function_exists('wc_create_page')) { return; } $pages = apply_filters('woocommerce_create_pages', array('unsubscribe' => array('name' => _x('unsubscribe', 'Page slug', 'ywrr'), 'title' => _x('Unsubscribe', 'Page title', 'ywrr'), 'content' => '[ywrr_unsubscribe]'))); foreach ($pages as $key => $page) { wc_create_page(esc_sql($page['name']), 'ywrr_' . $key . '_page_id', $page['title'], $page['content'], !empty($page['parent']) ? wc_get_page_id($page['parent']) : ''); } $unsubscribe_page = array('ID' => get_option('ywrr_unsubscribe_page_id'), 'post_status' => 'ywrr-unsubscribe'); wp_update_post($unsubscribe_page); }
/** * Install default settings & pages * * @since 1.0.0 * @see SV_WC_Plugin::install() */ protected function install() { // install default "content restricted" page $title = _x('Content restricted', 'Page title', WC_Memberships::TEXT_DOMAIN); $slug = _x('content-restricted', 'Page slug', WC_Memberships::TEXT_DOMAIN); $content = '[wcm_content_restricted]'; wc_create_page(esc_sql($slug), 'wc_memberships_redirect_page_id', $title, $content); // include settings so we can install defaults include_once WC()->plugin_path() . '/includes/admin/settings/class-wc-settings-page.php'; $settings = (require_once $this->get_plugin_path() . '/includes/admin/class-wc-memberships-settings.php'); // install default settings for each section foreach ($settings->get_sections() as $section => $label) { foreach ($settings->get_settings($section) as $setting) { if (isset($setting['default'])) { update_option($setting['id'], $setting['default']); } } } }
public static function activate_plugin() { global $wp_rewrite; $errors = self::check_requirements(); if (empty($errors)) { WC_BooXtream::add_rewrite_rules(); $wp_rewrite->flush_rules(); /* * Create page for processing asynchronous request to BooXtream */ $slug = __('download_processing', 'woocommerce_booxtream'); $title = __('Your download is not ready yet', 'woocommerce_booxtream'); $content = '<p>' . __('We are currently processing your download, please try again in a few seconds', 'woocommerce_booxtream') . '</p>'; wc_create_page(esc_sql($slug), 'woocommerce_download_processing_page_id', $title, $content, ''); return; } // Suppress "Plugin activated" notice. unset($_GET['activate']); // this plugin's name $name = get_file_data(__FILE__, array('Plugin Name'), 'plugin'); if (count($errors) > 0) { printf('<div class="error"><p>%1$s</p>' . '<p><i>%2$s</i> ' . __('has been deactivated', 'woocommerce_booxtream') . '</p></div>', join('</p><p>', $errors), $name[0]); deactivate_plugins(plugin_basename(__FILE__)); } // this will trigger the much coveted fatal error instead of 'unexpected output' exit; }
/** * 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 → 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; } } } }
/** * Create pages that the plugin relies on, storing page id's in variables. * * @access public * @return void */ public static function create_pages() { $pages = apply_filters('woocommerce_gzd_create_pages', array('data_security' => array('name' => _x('data-security', 'Page slug', 'woocommerce-germanized'), 'title' => _x('Data Security Statement', 'Page title', 'woocommerce-germanized'), 'content' => ''), 'imprint' => array('name' => _x('imprint', 'Page slug', 'woocommerce-germanized'), 'title' => _x('Imprint', 'Page title', 'woocommerce-germanized'), 'content' => ''), 'terms' => array('name' => _x('terms', 'Page slug', 'woocommerce-germanized'), 'title' => _x('Terms & Conditions', 'Page title', 'woocommerce-germanized'), 'content' => ''), 'revocation' => array('name' => _x('revocation', 'Page slug', 'woocommerce-germanized'), 'title' => _x('Power of Revocation', 'Page title', 'woocommerce-germanized'), 'content' => ''), 'shipping_costs' => array('name' => _x('shipping-methods', 'Page slug', 'woocommerce-germanized'), 'title' => _x('Shipping Methods', 'Page title', 'woocommerce-germanized'), 'content' => ''), 'payment_methods' => array('name' => _x('payment-methods', 'Page slug', 'woocommerce-germanized'), 'title' => _x('Payment Methods', 'Page title', 'woocommerce-germanized'), 'content' => '[' . apply_filters('woocommerce_gzd_payment_methods_shortcode_tag', 'payment_methods_info') . ']'))); foreach ($pages as $key => $page) { wc_create_page(esc_sql($page['name']), 'woocommerce_' . $key . '_page_id', $page['title'], $page['content'], !empty($page['parent']) ? wc_get_page_id($page['parent']) : ''); } }
public static function create_plugins_page() { $become_a_vendor_page = get_option('yith_wpv_become_a_vendor_page_id'); if ($become_a_vendor_page === false) { /* wc_create_page( $slug, $option, $page_title, $page_content, $post_parent ) */ $page_id = wc_create_page('become-a-vendor', 'yith_wpv_become_a_vendor_page_id', __('Become a vendor', 'yith_wc_product_vendors'), '[yith_wcmv_become_a_vendor]', 0); } $terms_and_conditions_page = get_option('yith_wpv_terms_and_conditions_page_id'); if ($terms_and_conditions_page === false) { /* wc_create_page( $slug, $option, $page_title, $page_content, $post_parent ) */ $page_id = wc_create_page('Vendors Terms and conditions', 'yith_wpv_terms_and_conditions_page_id', __('Terms and Conditions for Vendors', 'yith_wc_product_vendors'), '', 0); } }