Esempio n. 1
1
 /**
  * AJAX apply coupon on checkout page
  */
 public function apply_coupon()
 {
     check_ajax_referer('apply-coupon', 'security');
     if (!empty($_POST['coupon_code'])) {
         WC()->cart->add_discount(sanitize_text_field($_POST['coupon_code']));
     } else {
         wc_add_notice(WC_Coupon::get_generic_coupon_error(WC_Coupon::E_WC_COUPON_PLEASE_ENTER), 'error');
     }
     wc_print_notices();
     die;
 }
function wc_redirects__add_to_cart_redirect($url)
{
    static $cached_result = null;
    if (isset($cached_result)) {
        return $cached_result;
    }
    if (!isset($_REQUEST['add-to-cart'])) {
        return $url;
    }
    $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_REQUEST['add-to-cart']));
    $selected_redirection_type = get_post_meta($product_id, WC_REDIRECTS__REDIRECTION_TYPE_META_NAME, true);
    if (!empty($selected_redirection_type)) {
        foreach (wc_redirects__get_valid_redirection_types() as $redirection_type) {
            if ($redirection_type['name'] === $selected_redirection_type) {
                $result = call_user_func($redirection_type['callback']);
                if ($result === false) {
                    wc_add_notice("Item added to cart, but redirection " . "to {$redirection_type['label']} failed.");
                } else {
                    $url = $result;
                }
                break;
            }
        }
    }
    return $cached_result = $url;
}
 /**
  * Calculate shipping for the cart
  */
 public static function calculate_shipping()
 {
     try {
         WC()->shipping->reset_shipping();
         $country = wc_clean($_POST['calc_shipping_country']);
         $state = wc_clean(isset($_POST['calc_shipping_state']) ? $_POST['calc_shipping_state'] : '');
         $postcode = apply_filters('woocommerce_shipping_calculator_enable_postcode', true) ? wc_clean($_POST['calc_shipping_postcode']) : '';
         $city = apply_filters('woocommerce_shipping_calculator_enable_city', false) ? wc_clean($_POST['calc_shipping_city']) : '';
         if ($postcode && !WC_Validation::is_postcode($postcode, $country)) {
             throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce'));
         } elseif ($postcode) {
             $postcode = wc_format_postcode($postcode, $country);
         }
         if ($country) {
             WC()->customer->set_location($country, $state, $postcode, $city);
             WC()->customer->set_shipping_location($country, $state, $postcode, $city);
         } else {
             WC()->customer->set_to_base();
             WC()->customer->set_shipping_to_base();
         }
         WC()->customer->calculated_shipping(true);
         wc_add_notice(__('Shipping costs updated.', 'woocommerce'), 'notice');
         do_action('woocommerce_calculated_shipping');
     } catch (Exception $e) {
         if (!empty($e)) {
             wc_add_notice($e->getMessage(), 'error');
         }
     }
 }
Esempio n. 4
0
 public static function checkout_validate_vat()
 {
     check_ajax_referer('update-order-review', 'security');
     if (!isset($_POST['vat_id']) || !isset($_POST['country'])) {
         die;
     }
     $country = sanitize_text_field($_POST['country']);
     $vat_id = trim(preg_replace("/[^a-z0-9.]+/i", "", sanitize_text_field($_POST['vat_id'])));
     // Strip away country code
     if (substr($vat_id, 0, 2) == $country) {
         $vat_id = substr($vat_id, 2);
     }
     if (WC_GZDP_VAT_Helper::instance()->validate($country, $vat_id)) {
         // Add price vat filters..
         add_filter('woocommerce_cart_get_taxes', array(__CLASS__, "remove_taxes"), 0, 2);
         echo json_encode(array('valid' => true, 'vat_id' => $country . '-' . $vat_id));
     } else {
         wc_add_notice(__('VAT ID seems to be invalid.', 'woocommerce-germanized-pro'), 'error');
         ob_start();
         wc_print_notices();
         $messages = ob_get_clean();
         echo json_encode(array('valid' => false, 'error' => $messages));
     }
     die;
 }
 /**
  * Cancel a booking.
  */
 public static function cancel_booking()
 {
     if (isset($_GET['cancel_booking']) && isset($_GET['booking_id'])) {
         $booking_id = absint($_GET['booking_id']);
         $booking = get_wc_booking($booking_id);
         $booking_can_cancel = $booking->has_status(apply_filters('woocommerce_valid_booking_statuses_for_cancel', array('unpaid', 'pending-confirmation', 'confirmed', 'paid')));
         $redirect = $_GET['redirect'];
         if ($booking->has_status('cancelled')) {
             // Already cancelled - take no action
         } elseif ($booking_can_cancel && $booking->id == $booking_id && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'woocommerce-bookings-cancel_booking')) {
             // Cancel the booking
             $booking->update_status('cancelled');
             WC_Cache_Helper::get_transient_version('bookings', true);
             // Message
             wc_add_notice(apply_filters('woocommerce_booking_cancelled_notice', __('Your booking was cancelled.', 'woocommerce-bookings')), apply_filters('woocommerce_booking_cancelled_notice_type', 'notice'));
             do_action('woocommerce_bookings_cancelled_booking', $booking->id);
         } elseif (!$booking_can_cancel) {
             wc_add_notice(__('Your booking can no longer be cancelled. Please contact us if you need assistance.', 'woocommerce-bookings'), 'error');
         } else {
             wc_add_notice(__('Invalid booking.', 'woocommerce-bookings'), 'error');
         }
         if ($redirect) {
             wp_safe_redirect($redirect);
             exit;
         }
     }
 }
Esempio n. 6
0
function wc_minimum_order_amount()
{
    global $woocommerce;
    $postcode = get_user_meta(get_current_user_id(), 'shipping_postcode', true);
    if (strstr(' 90024 90027 90028 90029 90034 90036 90038 90039 90046 90048 90064 90066 90067 90068 90069 90095 90230 90291 90401 90402 90403 90404 90405 91505 91506 91602 91604 91607 91608 90010 90012 90019 90020 90025 90232 91601 91606 90073 90031 90090 90005 90004 90026 90035 90056 90211 90212 ', $postcode)) {
        $minimum = 60;
    } else {
        if (strstr(' 90045 90049 90016 90292 91423 90008 90018 90045 90049 90210 90245 90272 90293 90077 90094 91403 91436 90079 90210 90007 90015 90017 90057 90071 90089 90266 90013 90014 ', $postcode)) {
            $minimum = 100;
        } else {
            $minimum = false;
        }
    }
    if ($minimum == false) {
        wc_print_notice(sprintf('We are unable to service your area at this time. Please give us a call at (323) 450-7708 to discuss arrangements for your delivery.', wc_price($minimum), wc_price(WC()->cart->subtotal)), 'error');
        echo "<script>\n\t\t\t\tjQuery(document).ready(function(\$) {\n\t\t\t\t\t\$('.checkout-button').addClass('disabled');\n\t\t\t\t\t\$('.checkout-button').click(function(e) { e.preventDefault(); });\n\t\t\t\t});\n\t\t\t</script>";
    } elseif (WC()->cart->subtotal < $minimum) {
        if (is_cart()) {
            wc_print_notice(sprintf('Based on your zip code ' . $postcode . ', you must have an order with a minimum of %s to checkout. Your current order total is %s.', wc_price($minimum), wc_price(WC()->cart->subtotal)), 'error');
            echo "\n\t\t\t\t<script>\n\t\t\t\t\tjQuery(document).ready(function(\$) {\n\t\t\t\t\t\t\$('.checkout-button').addClass('disabled');\n\t\t\t\t\t\t\$('.checkout-button').click(function(e) { e.preventDefault(); });\n\t\t\t\t\t});\n\t\t\t\t</script>";
        } else {
            wc_add_notice(sprintf('Based on your zip code ' . $postcode . ', you must have an order with a minimum of %s to checkout. Your current order total is %s.', wc_price($minimum), wc_price(WC()->cart->subtotal)), 'error');
        }
    }
}
 /**
  * Handle a renewal url
  */
 public function renew_handler()
 {
     if (!empty($_GET['renew_licence']) && is_user_logged_in()) {
         global $wpdb;
         $licence_key = sanitize_text_field($_GET['renew_licence']);
         $licence = $wpdb->get_row($wpdb->prepare("\n\t\t\t\tSELECT * FROM {$wpdb->prefix}wp_plugin_licencing_licences\n\t\t\t\tWHERE licence_key = %s\n\t\t\t\tAND ( user_id = %d OR user_id = 0 )\n\t\t\t", $licence_key, get_current_user_id()));
         // Renewable?
         if (!$licence) {
             wc_add_notice(__('Invalid licence', 'wp-plugin-licencing'), 'error');
             return;
         }
         if (!$licence->date_expires || strtotime($licence->date_expires) > current_time('timestamp')) {
             wc_add_notice(__('This licence does not need to be renewed yet', 'wp-plugin-licencing'), 'notice');
             return;
         }
         // Purchasable?
         $product = get_product($licence->product_id);
         if (!$product->is_purchasable()) {
             wc_add_notice(__('This product can no longer be purchased', 'wp-plugin-licencing'), 'error');
             return;
         }
         // Add to cart
         WC()->cart->empty_cart();
         WC()->cart->add_to_cart($licence->product_id, 1, '', '', array('renewing_key' => $licence_key));
         // Message
         wc_add_notice(sprintf(__('The product has been added to your cart with a %d%% discount.', 'wp-plugin-licencing'), apply_filters('wp_plugin_licencing_renewal_discount_percent', 30)), 'success');
         // Redirect to checkout
         wp_redirect(get_permalink(wc_get_page_id('checkout')));
         exit;
     }
 }
 public function validate_add_cart_item($passed, $product_id, $qty)
 {
     $product = get_product($product_id);
     if ($product->product_type !== 'trip') {
         return $passed;
     }
     $stockOk = false;
     foreach ($this->package_types as $package) {
         if (isset($_POST['wc_trip_' . $package . "_package"])) {
             $post = $_POST['wc_trip_' . $package . "_package"];
             $stockCheck = $product->check_package_stock($package, $post);
             if ($stockCheck) {
                 $stockOk = true;
             } else {
                 wc_add_notice("Sorry, " . $post . " is out of stock", 'error');
                 return false;
             }
         }
     }
     if ($stockOk) {
         return true;
     } else {
         wc_add_notice("Couldn't find specified packages, try again", 'error');
         return false;
     }
 }
/**
 * Handle redirects before content is output - hooked into template_redirect so is_page works.
 */
function wc_template_redirect()
{
    global $wp_query, $wp;
    // When default permalinks are enabled, redirect shop page to post type archive url
    if (!empty($_GET['page_id']) && '' === get_option('permalink_structure') && $_GET['page_id'] == wc_get_page_id('shop')) {
        wp_safe_redirect(get_post_type_archive_link('product'));
        exit;
    } elseif (is_page(wc_get_page_id('checkout')) && WC()->cart->is_empty() && empty($wp->query_vars['order-pay']) && !isset($wp->query_vars['order-received'])) {
        wc_add_notice(__('Checkout is not available whilst your cart is empty.', 'woocommerce'), 'notice');
        wp_redirect(wc_get_page_permalink('cart'));
        exit;
    } elseif (isset($wp->query_vars['customer-logout'])) {
        wp_redirect(str_replace('&amp;', '&', wp_logout_url(wc_get_page_permalink('myaccount'))));
        exit;
    } elseif (is_search() && is_post_type_archive('product') && apply_filters('woocommerce_redirect_single_search_result', true) && 1 === absint($wp_query->found_posts)) {
        $product = wc_get_product($wp_query->post);
        if ($product && $product->is_visible()) {
            wp_safe_redirect(get_permalink($product->id), 302);
            exit;
        }
    } elseif (is_add_payment_method_page()) {
        WC()->payment_gateways();
    } elseif (is_checkout()) {
        // Buffer the checkout page
        ob_start();
        // Ensure gateways and shipping methods are loaded early
        WC()->payment_gateways();
        WC()->shipping();
    }
}
function validate_custom_checkout_field_process()
{
    // Check if set, if its not set add an error.
    if (isset($_POST['latitude']) && !$_POST['latitude'] || isset($_POST['longitude']) && !$_POST['longitude']) {
        wc_add_notice(__('Please define your location on the map.'), 'error');
    }
}
Esempio n. 11
0
function plp_cartcontent()
{
    global $woocommerce;
    $poj = new WC_Product_Factory();
    $count = 0;
    if (isset($_POST['productadd'])) {
        $woocommerce->cart = new WC_Cart();
        $woocommerce->cart->get_cart_from_session();
        foreach ($_POST['productadd'] as $productId => $quantity) {
            $quantity = (int) $quantity;
            $productId = (int) $productId;
            $product = $poj->get_product($productId);
            if ($quantity > 0) {
                if (isset($product->variation_id) && isset($product->parent)) {
                    $woocommerce->cart->add_to_cart($product->parent->id, $quantity, $product->variation_id, $product->get_variation_attributes());
                } else {
                    $woocommerce->cart->add_to_cart($productId, $quantity);
                }
                $count++;
            }
        }
        if ($count >= 1) {
            $success_msg = get_option('plp_custom_success_msg');
            wc_add_notice($success_msg, "success");
        } else {
            $error_msg = get_option('plp_custom_err_msg');
            wc_add_notice($error_msg, "error");
        }
    }
}
 /**
  * Setup the cart for paying for a delayed initial payment for a subscription.
  *
  * @since 2.0
  */
 public function maybe_setup_cart()
 {
     global $wp;
     if (isset($_GET['pay_for_order']) && isset($_GET['key']) && isset($wp->query_vars['order-pay'])) {
         // Pay for existing order
         $order_key = $_GET['key'];
         $order_id = isset($wp->query_vars['order-pay']) ? $wp->query_vars['order-pay'] : absint($_GET['order_id']);
         $order = wc_get_order($wp->query_vars['order-pay']);
         if ($order->order_key == $order_key && $order->has_status(array('pending', 'failed')) && !wcs_order_contains_subscription($order, array('renewal', 'resubscribe'))) {
             $subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => 'parent'));
             if (get_current_user_id() !== $order->get_user_id()) {
                 wc_add_notice(__('That doesn\'t appear to be your order.', 'woocommerce-subscriptions'), 'error');
                 wp_safe_redirect(get_permalink(wc_get_page_id('myaccount')));
                 exit;
             } elseif (!empty($subscriptions)) {
                 // Setup cart with all the original order's line items
                 $this->setup_cart($order, array('order_id' => $order_id));
                 WC()->session->set('order_awaiting_payment', $order_id);
                 // Set cart hash for orders paid in WC >= 2.6
                 $this->set_cart_hash($order_id);
                 wp_safe_redirect(WC()->cart->get_checkout_url());
                 exit;
             }
         }
     }
 }
Esempio n. 13
0
 /**
  * @return void
  */
 public function active_free_order()
 {
     try {
         $response = array();
         $fb_id = isset($_POST['post_id']) ? $_POST['post_id'] : 0;
         $redirect_url = isset($_POST['redirect_url']) ? $_POST['redirect_url'] : '';
         if (!$fb_id || !$redirect_url || !is_user_logged_in()) {
             throw new Exception(__('Không thể kích hoạt', NDV_WOO));
             return false;
         }
         $user = wp_get_current_user();
         update_user_meta($user->ID, 'ndv_share', $fb_id);
         $response['status'] = 'success';
         $response['redirect'] = $redirect_url;
         if (is_ajax()) {
             echo '<!--WC_START-->' . json_encode($response) . '<!--WC_END-->';
             exit;
         } else {
             wp_redirect($response['redirect']);
             exit;
         }
     } catch (Exception $e) {
         if (!empty($e)) {
             wc_add_notice($e->getMessage(), 'error');
         }
     }
     if (is_ajax()) {
         ob_start();
         wc_print_notices();
         $messages = ob_get_clean();
         echo '<!--WC_START-->' . json_encode(array('result' => 'failure', 'messages' => isset($messages) ? $messages : '')) . '<!--WC_END-->';
         exit;
     }
 }
Esempio n. 14
0
function wc_gateway_ppec_format_paypal_api_exception($errors)
{
    $error_strings = array();
    foreach ($errors as $error) {
        $error_strings[] = $error->maptoBuyerFriendlyError();
    }
    wc_add_notice(__('Payment error:', 'woocommerce-gateway-paypal-express-checkout') . '<ul><li>' . implode('</li><li>', $error_strings) . '</li></ul>', 'error');
}
 /**
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since  151229
  */
 public function checkoutProcess()
 {
     if ($this->isTimologioRequest()) {
         $valid = $this->validateInvoicePostFields();
         if (count($valid) < count($this->fields)) {
             wc_add_notice(__('Please fill all invoice fields', 'wc-timologio'), 'error');
         }
     }
 }
 /**
  * Add an error
  */
 public function add_error($error)
 {
     if (function_exists('wc_add_notice')) {
         wc_add_notice($error, 'error');
     } else {
         global $woocommerce;
         $woocommerce->add_error($error);
     }
 }
 function woocommerce_billing_fields_ro_process()
 {
     global $woocommerce;
     // Check if set, if its not set add an error. This one is only required for companies
     if (isset($_POST['billing_company']) && !empty($_POST['billing_company'])) {
         if (empty($_POST['wbfr_cif']) || empty($_POST['wbfr_regcom']) || empty($_POST['wbfr_cont_banca']) || empty($_POST['wbfr_banca'])) {
             wc_add_notice(__('Nu ai introdus toate câmpurile de la <strong>Date facturare firmă</strong> din partea de jos a paginii'), 'error');
         }
     }
 }
Esempio n. 18
0
/**
 * some WC functions wrapper
 * */
function nm_wc_add_notice($string, $type = "error")
{
    global $woocommerce;
    if (version_compare($woocommerce->version, 2.1, ">=")) {
        wc_add_notice($string, $type);
        // Use new, updated functions
    } else {
        $woocommerce->add_error($string);
    }
}
 public function coupon_validation()
 {
     $wc = WC();
     $coupons = $wc->cart->get_coupons();
     if (empty($coupons)) {
         $options = get_option('foa_woo_force_coupon', '');
         $errornotice = empty($options['errornotice']) ? __('Coupon is a required field. Please enter a coupon.', 'woo-force-coupon') : $options['errornotice'];
         wc_add_notice($errornotice, 'error');
     }
 }
 public function __construct()
 {
     $this->paydunya_errors = new WP_Error();
     $this->id = 'paydunya';
     $this->medthod_title = 'PAYDUNYA';
     $this->icon = apply_filters('woocommerce_paydunya_icon', plugins_url('assets/images/logo.png', __FILE__));
     $this->has_fields = false;
     $this->init_form_fields();
     $this->init_settings();
     $this->title = $this->settings['title'];
     $this->description = $this->settings['description'];
     $this->live_master_key = $this->settings['master_key'];
     $this->live_private_key = $this->settings['live_private_key'];
     $this->live_token = $this->settings['live_token'];
     $this->test_private_key = $this->settings['test_private_key'];
     $this->test_token = $this->settings['test_token'];
     $this->sandbox = $this->settings['sandbox'];
     $this->sms = $this->settings['sms'];
     $this->sms_url = $this->settings['sms_url'];
     $this->sms_message = $this->settings['sms_message'];
     if ($this->settings['sandbox'] == "yes") {
         $this->posturl = 'https://app.paydunya.com/sandbox-api/v1/checkout-invoice/create';
         $this->geturl = 'https://app.paydunya.com/sandbox-api/v1/checkout-invoice/confirm/';
     } else {
         $this->posturl = 'https://app.paydunya.com/api/v1/checkout-invoice/create';
         $this->geturl = 'https://app.paydunya.com/api/v1/checkout-invoice/confirm/';
     }
     $this->msg['message'] = "";
     $this->msg['class'] = "";
     if (isset($_REQUEST["paydunya"])) {
         wc_add_notice($_REQUEST["paydunya"], "error");
     }
     if (isset($_REQUEST["token"]) && $_REQUEST["token"] != "") {
         $token = trim($_REQUEST["token"]);
         $this->check_paydunya_response($token);
     } else {
         $query_str = $_SERVER['QUERY_STRING'];
         $query_str_arr = explode("?", $query_str);
         foreach ($query_str_arr as $value) {
             $data = explode("=", $value);
             if (trim($data[0]) == "token") {
                 $token = isset($data[1]) ? trim($data[1]) : "";
                 if ($token != "") {
                     $this->check_paydunya_response($token);
                 }
                 break;
             }
         }
     }
     if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) {
         add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this, 'process_admin_options'));
     } else {
         add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
     }
 }
 /**
  * Output a message or error
  * @param  string $message
  * @param  string $type
  */
 public function debug($message, $type = 'notice')
 {
     if ($this->debug && !is_admin()) {
         //WF: do not call wc_add_notice from admin.
         if (version_compare(WOOCOMMERCE_VERSION, '2.1', '>=')) {
             wc_add_notice($message, $type);
         } else {
             global $woocommerce;
             $woocommerce->add_message($message);
         }
     }
 }
 /**
  * @since 1.1.0 of SA_WC_Compatibility
  */
 public static function wc_add_notice($message, $notice_type = 'success')
 {
     if (self::is_wc_21()) {
         wc_add_notice($message, $notice_type);
     } else {
         global $woocommerce;
         if ('error' == $notice_type) {
             $woocommerce->add_error($message);
         } else {
             $woocommerce->add_message($message);
         }
     }
 }
 public function check_vat_exemption($post_data = array())
 {
     $tax_address = WC()->customer->get_taxable_address();
     WC()->customer->set_is_vat_exempt(false);
     if (isset($post_data['billing_vat_id']) && isset($tax_address[0]) && !empty($tax_address[0]) && !empty($post_data['billing_vat_id'])) {
         $vat_id = $this->parse_vat_number($post_data['billing_vat_id'], $tax_address[0]);
         if (WC_GZDP_VAT_Helper::instance()->validate($tax_address[0], $vat_id)) {
             WC()->customer->set_is_vat_exempt(true);
         } else {
             wc_add_notice(__('VAT ID seems to be invalid.', 'woocommerce-germanized-pro'), 'error');
         }
     }
 }
Esempio n. 24
0
 /**
  * AJAX remove coupon on cart and checkout page
  */
 public static function remove_coupon()
 {
     check_ajax_referer('remove-coupon', 'security');
     $coupon = wc_clean($_POST['coupon']);
     if (!isset($coupon) || empty($coupon)) {
         wc_add_notice(__('Sorry there was a problem removing this coupon.', 'woocommerce'));
     } else {
         WC()->cart->remove_coupon($coupon);
         wc_add_notice(__('Coupon has been removed.', 'woocommerce'));
     }
     wc_print_notices();
     die;
 }
 public function validate_email_address($confirm_email = '')
 {
     global $woocommerce;
     $billing_email = $woocommerce->checkout->posted['billing_email'];
     if (strtolower($confirm_email) != strtolower($billing_email)) {
         $notice = sprintf(__('%1$sEmail addresses%2$s do not match.', 'wc_emailvalidation'), '<strong>', '</strong>');
         if (version_compare(WC_VERSION, '2.3', '<')) {
             $woocommerce->add_error($notice);
         } else {
             wc_add_notice($notice, 'error');
         }
     }
     return $confirm_email;
 }
Esempio n. 26
0
 /**
  * Output a message or error
  * @param  string $message
  * @param  string $type
  */
 public function debug($message, $type = 'notice')
 {
     // Hard coding to 'notice' as recently noticed 'error' is breaking with wc_add_notice.
     $type = 'notice';
     if ($this->debug && !is_admin()) {
         //WF: do not call wc_add_notice from admin.
         if (version_compare(WOOCOMMERCE_VERSION, '2.1', '>=')) {
             wc_add_notice($message, $type);
         } else {
             global $woocommerce;
             $woocommerce->add_message($message);
         }
     }
 }
 /**
  * Output the cart shortcode.
  *
  * @param array $atts
  */
 public static function output($atts)
 {
     // Check cart class is loaded or abort
     if (is_null(WC()->cart)) {
         return;
     }
     // Constants
     if (!defined('WOOCOMMERCE_CART')) {
         define('WOOCOMMERCE_CART', true);
     }
     // Update Shipping
     if (!empty($_POST['calc_shipping']) && wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-cart')) {
         try {
             WC()->shipping->reset_shipping();
             $country = wc_clean($_POST['calc_shipping_country']);
             $state = isset($_POST['calc_shipping_state']) ? wc_clean($_POST['calc_shipping_state']) : '';
             $postcode = apply_filters('woocommerce_shipping_calculator_enable_postcode', true) ? wc_clean($_POST['calc_shipping_postcode']) : '';
             $city = apply_filters('woocommerce_shipping_calculator_enable_city', false) ? wc_clean($_POST['calc_shipping_city']) : '';
             if ($postcode && !WC_Validation::is_postcode($postcode, $country)) {
                 throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce'));
             } elseif ($postcode) {
                 $postcode = wc_format_postcode($postcode, $country);
             }
             if ($country) {
                 WC()->customer->set_location($country, $state, $postcode, $city);
                 WC()->customer->set_shipping_location($country, $state, $postcode, $city);
             } else {
                 WC()->customer->set_to_base();
                 WC()->customer->set_shipping_to_base();
             }
             WC()->customer->calculated_shipping(true);
             wc_add_notice(__('Shipping costs updated.', 'woocommerce'), 'notice');
             do_action('woocommerce_calculated_shipping');
         } catch (Exception $e) {
             if (!empty($e)) {
                 wc_add_notice($e->getMessage(), 'error');
             }
         }
     }
     // Check cart items are valid
     do_action('woocommerce_check_cart_items');
     // Calc totals
     WC()->cart->calculate_totals();
     if (sizeof(WC()->cart->get_cart()) == 0) {
         wc_get_template('cart/cart-empty.php');
     } else {
         wc_get_template('cart/cart.php');
     }
 }
 /**
  * @param array $response
  * @param       $endpoint
  *
  * @return bool
  */
 private function check_response($response, $endpoint)
 {
     if (isset($response['errors']) && !empty($response['errors'])) {
         foreach ($response['errors'] as $error) {
             $message = $this->get_error_message($error, $endpoint);
             if (function_exists('wc_add_notice')) {
                 wc_add_notice(__($message, VINDI_IDENTIFIER), 'error');
             }
             $this->last_error = $message;
         }
         return false;
     }
     $this->last_error = '';
     return true;
 }
 /**
  * Submit a comment for an order
  *
  * @param object $orders
  *
  * @return unknown
  */
 public static function new_comment($orders)
 {
     global $woocommerce;
     $user = wp_get_current_user();
     $user = $user->ID;
     // Security
     if (!wp_verify_nonce($_POST['_wpnonce'], 'add-comment')) {
         return false;
     }
     // Check if this product belongs to the vendor submitting the comment
     $product_id = (int) $_POST['product_id'];
     $author = WCV_Vendors::get_vendor_from_product($product_id);
     if ($author != $user) {
         return false;
     }
     // Find the order belonging to this comment
     foreach ($orders as $order) {
         if ($order->order_id == $_POST['order_id']) {
             $found_order = $order;
             break;
         }
     }
     // No order was found
     if (empty($found_order)) {
         return false;
     }
     // Don't submit empty comments
     if (empty($_POST['comment_text'])) {
         wc_add_notice(__('You\'ve left the comment field empty!', 'wcvendors'), 'error');
         return false;
     }
     // Only submit if the order has the product belonging to this vendor
     $found_order = new WC_Order($found_order->order_id);
     $valid_order = false;
     foreach ($found_order->get_items() as $item) {
         if ($item['product_id'] == $product_id) {
             $valid_order = true;
             break;
         }
     }
     if ($valid_order) {
         $comment = esc_textarea($_POST['comment_text']);
         add_filter('woocommerce_new_order_note_data', array(__CLASS__, 'filter_comment'), 10, 2);
         $found_order->add_order_note($comment, 1);
         remove_filter('woocommerce_new_order_note_data', array(__CLASS__, 'filter_comment'), 10, 2);
         wc_add_notice(__('Success. The customer has been notified of your comment.', 'wcvendors'), 'success');
     }
 }
 /**
  * Make a card as default method
  */
 public function default_card()
 {
     if (!isset($_POST['stripe_default_card']) || !is_account_page()) {
         return;
     }
     $stripe_customer = new WC_Stripe_Customer(get_current_user_id());
     $stripe_customer_id = $stripe_customer->get_id();
     $default_source = sanitize_text_field($_POST['stripe_default_card']);
     if (!is_user_logged_in() || !$stripe_customer_id || !wp_verify_nonce($_POST['_wpnonce'], "stripe_default_card")) {
         wp_die(__('Unable to make default card, please try again', 'woocommerce-gateway-stripe'));
     }
     if (!$stripe_customer->set_default_card($default_source)) {
         wc_add_notice(__('Unable to update default card.', 'woocommerce-gateway-stripe'), 'error');
     } else {
         wc_add_notice(__('Default card updated.', 'woocommerce-gateway-stripe'), 'success');
     }
 }