function woocommerce_apply_giftcard($giftcard_code) { global $wpdb; if (!empty($_POST['giftcard_code'])) { $giftcard_number = sanitize_text_field($_POST['giftcard_code']); if (!isset(WC()->session->giftcard_post)) { $giftcard_id = wpr_get_giftcard_by_code($giftcard_number); if ($giftcard_id) { $current_date = date("Y-m-d"); $cardExperation = wpr_get_giftcard_expiration($giftcard_id); if (strtotime($current_date) <= strtotime($cardExperation) || strtotime($cardExperation) == '') { if (wpr_get_giftcard_balance($giftcard_id) > 0) { WC()->session->giftcard_post = $giftcard_id; wc_add_notice(__('Gift card applied successfully.', 'rpgiftcards'), 'success'); } else { wc_add_notice(__('Gift Card does not have a balance!', 'rpgiftcards'), 'error'); } } else { wc_add_notice(__('Gift Card has expired!', 'rpgiftcards'), 'error'); // Giftcard Entered has expired } } else { wc_add_notice(__('Gift Card does not exist!', 'rpgiftcards'), 'error'); // Giftcard Entered does not exist } } else { wc_add_notice(__('Gift Card already in the cart!', 'rpgiftcards'), 'error'); // You already have a gift card in the cart } wc_print_notices(); } }
/** * 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; }
/** * * Adds a custom form to the product page. * **/ public function easy_booking_before_add_to_cart_button() { global $post, $product; $product = wc_get_product($product->id); // Is product bookable ? $is_bookable = get_post_meta($product->id, '_booking_option', true); $info_text = $this->options['easy_booking_info_text']; $start_date_text = $this->options['easy_booking_start_date_text']; $end_date_text = $this->options['easy_booking_end_date_text']; $product_price = $product->get_price(); $args = apply_filters('easy_booking_new_price_args', array()); // Product is bookable if (isset($is_bookable) && $is_bookable === 'yes') { // Display info text if (isset($info_text) && !empty($info_text)) { echo apply_filters('easy_booking_before_picker_form', '<div class="woocommerce-info">' . wpautop(esc_textarea($info_text)) . '</div>', $info_text); } echo '<div class="wc_ebs_errors">' . wc_print_notices() . '</div>'; // Please do not remove inputs' attributes (classes, ids, etc.) echo '<div class="wceb_picker_wrap">'; echo apply_filters('easy_booking_picker_form', '<p class="form-row form-row-wide"> <label for="start_date">' . esc_html($start_date_text) . '</label> <input type="hidden" id="variation_id" name="variation_id" data-product_id="' . absint($product->id) . '" value=""> <input type="text" id="start_date" class="datepicker datepicker_start" data-value="" placeholder="' . esc_html($start_date_text) . '"> </p> <p class="form-row form-row-wide"> <label for="end_date">' . esc_html($end_date_text) . '</label> <input type="text" id="end_date" class="datepicker datepicker_end" data-value="" placeholder="' . esc_html($end_date_text) . '"> </p>', $start_date_text, $end_date_text, $product); echo '</div>'; // If product is not variable, add a new price field before add to cart button if (!$product->is_type('variable')) { echo '<p class="booking_price"><span class="price">' . wc_price($product_price, $args) . '</span></p>'; } } }
/** * @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; } }
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; }
function WooComposer_Product($atts) { $product_style = ''; extract(shortcode_atts(array("product_style" => ""), $atts)); $output = ''; ob_start(); $output .= '<div class="woocommerce woo-msg">'; wc_print_notices(); $output .= ob_get_clean(); $output .= '</div>'; $template = 'design-single-' . $product_style . '.php'; require_once $template; $function = 'WooComposer_Single_' . $product_style; $output .= $function($atts); return $output; }
/** * Outputs the thankyou page * * @access public * @param mixed $atts * @return void */ public static function output($atts) { wc_print_notices(); // Pay for order after checkout step if (isset($_GET['order'])) { $order_id = (int) $_GET['order']; } else { $order_id = 0; } WC()->cart->empty_cart(); if ($order_id > 0) { $order = new WC_Order($order_id); } else { $order = false; } wc_get_template('checkout/thankyou.php', array('order' => $order)); }
function woocomposer_grid_shortcode($atts) { $product_style = ''; extract(shortcode_atts(array("product_style" => ""), $atts)); $output = ''; ob_start(); $output .= '<div class="woocommerce">'; wc_print_notices(); $output .= ob_get_clean(); $output .= '</div>'; $uid = uniqid(); $output = '<div id="woo-grid-' . $uid . '" class="woocomposer_grid">'; $template = 'design-loop-' . $product_style . '.php'; require_once $template; $function = 'WooComposer_Loop_' . $product_style; $output .= $function($atts, 'grid'); $output .= "\n" . '</div>'; return $output; }
public function wc_quick_donation_handler($settings) { global $donation_box, $donation_price, $currency; $settings = shortcode_atts(array('type' => wcqd_get_option(WC_QD_DB . 'default_render_type'), 'grouped' => false, 'show_errors' => wcqd_get_option(WC_QD_DB . 'shortcode_show_errors'), 'selected_value' => wcqd_get_option(WC_QD_DB . 'pre_selected_project'), 'defined_amount' => false), $settings); $donation_box = WC_QD()->f()->generate_donation_selbox($settings['grouped'], $settings['type'], $settings['selected_value']); $donation_price = WC_QD()->f()->generate_price_box($settings['defined_amount']); $currency = get_woocommerce_currency_symbol(); $return_value = ''; $messages = ''; if ($settings['show_errors']) { ob_start(); wc_print_notices(); $return_value .= ob_get_clean(); ob_flush(); } do_action('wc_quick_donation_before_doantion_form', $return_value, $settings['type'], $settings['grouped']); $return_value .= WC_QD()->f()->load_template('donation-form.php', WC_QD_TEMPLATE, array('donation_box' => $donation_box, 'donation_price' => $donation_price, 'currency' => $currency)); do_action('wc_quick_donation_after_doantion_form', $return_value, $settings['type'], $settings['grouped']); return $return_value; }
/** * AJAX update order review on checkout */ public static function update_order_review() { ob_start(); check_ajax_referer('update-order-review', 'security'); if (!defined('WOOCOMMERCE_CHECKOUT')) { define('WOOCOMMERCE_CHECKOUT', true); } if (WC()->cart->is_empty()) { $data = array('fragments' => apply_filters('woocommerce_update_order_review_fragments', array('form.woocommerce-checkout' => '<div class="woocommerce-error">' . __('Sorry, your session has expired.', 'woocommerce') . ' <a href="' . home_url() . '" class="wc-backward">' . __('Return to homepage', 'woocommerce') . '</a></div>'))); wp_send_json($data); die; } do_action('woocommerce_checkout_update_order_review', $_POST['post_data']); $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); WC()->session->set('chosen_payment_method', empty($_POST['payment_method']) ? '' : $_POST['payment_method']); if (isset($_POST['country'])) { WC()->customer->set_country($_POST['country']); } if (isset($_POST['state'])) { WC()->customer->set_state($_POST['state']); } if (isset($_POST['postcode'])) { WC()->customer->set_postcode($_POST['postcode']); } if (isset($_POST['city'])) { WC()->customer->set_city($_POST['city']); } if (isset($_POST['address'])) { WC()->customer->set_address($_POST['address']); } if (isset($_POST['address_2'])) { WC()->customer->set_address_2($_POST['address_2']); } if (wc_ship_to_billing_address_only()) { if (isset($_POST['country'])) { WC()->customer->set_shipping_country($_POST['country']); } if (isset($_POST['state'])) { WC()->customer->set_shipping_state($_POST['state']); } if (isset($_POST['postcode'])) { WC()->customer->set_shipping_postcode($_POST['postcode']); } if (isset($_POST['city'])) { WC()->customer->set_shipping_city($_POST['city']); } if (isset($_POST['address'])) { WC()->customer->set_shipping_address($_POST['address']); } if (isset($_POST['address_2'])) { WC()->customer->set_shipping_address_2($_POST['address_2']); } } else { if (isset($_POST['s_country'])) { WC()->customer->set_shipping_country($_POST['s_country']); } if (isset($_POST['s_state'])) { WC()->customer->set_shipping_state($_POST['s_state']); } if (isset($_POST['s_postcode'])) { WC()->customer->set_shipping_postcode($_POST['s_postcode']); } if (isset($_POST['s_city'])) { WC()->customer->set_shipping_city($_POST['s_city']); } if (isset($_POST['s_address'])) { WC()->customer->set_shipping_address($_POST['s_address']); } if (isset($_POST['s_address_2'])) { WC()->customer->set_shipping_address_2($_POST['s_address_2']); } } WC()->cart->calculate_totals(); // Get order review fragment ob_start(); woocommerce_order_review(); $woocommerce_order_review = ob_get_clean(); // Get checkout payment fragment ob_start(); woocommerce_checkout_payment(); $woocommerce_checkout_payment = ob_get_clean(); // Get messages if reload checkout is not true $messages = ''; if (!isset(WC()->session->reload_checkout)) { ob_start(); wc_print_notices(); $messages = ob_get_clean(); } $data = array('result' => empty($messages) ? 'success' : 'failure', 'messages' => $messages, 'reload' => isset(WC()->session->reload_checkout) ? 'true' : 'false', 'fragments' => apply_filters('woocommerce_update_order_review_fragments', array('.woocommerce-checkout-review-order-table' => $woocommerce_order_review, '.woocommerce-checkout-payment' => $woocommerce_checkout_payment))); wp_send_json($data); die; }
/** * Print WooCommerce messages regardless of the version of WooCommerce running. * * @since version 1.4.5 */ public static function print_notices() { global $woocommerce; if (function_exists('wc_print_notices')) { wc_print_notices(); } else { // WC < 2.1 $woocommerce->show_messages(); } }
/** * Show messages * * @return string */ public static function shop_messages() { ob_start(); wc_print_notices(); return '<div class="woocommerce">' . ob_get_clean() . '</div>'; }
/** * Add custom template form my-account page * * @return void * @since 2.0.0 * @author Francesco Licandro <*****@*****.**> */ function yit_my_account_template() { if (function_exists('WC') && is_page(get_option('woocommerce_myaccount_page_id'))) { global $wp; if (is_user_logged_in()) { if (!is_rtl()) { echo '<div class="col-sm-3" id="my-account-sidebar">'; wc_get_template('/myaccount/my-account-menu.php'); echo '</div>'; } echo '<div class="col-sm-9" id="my-account-content">'; wc_print_notices(); if (!isset($wp->query_vars['recent-downloads']) && !isset($wp->query_vars['wishlist']) && !isset($wp->query_vars['edit-address']) && !isset($wp->query_vars['edit-account']) && !isset($wp->query_vars['view-order']) && !isset($wp->query_vars['lost-password'])) { wc_get_template('myaccount/my-orders.php', array('order_count' => 15)); } elseif (isset($wp->query_vars['recent-downloads'])) { wc_get_template('myaccount/my-downloads.php'); } elseif (isset($wp->query_vars['wishlist'])) { echo do_shortcode('[yith_wcwl_wishlist]'); } else { yit_content_loop(); } echo '</div>'; if (is_rtl()) { echo '<div class="col-sm-3" id="my-account-sidebar">'; wc_get_template('/myaccount/my-account-menu.php'); echo '</div>'; } } else { echo '<div class="row" id="my-account-content">'; if (isset($wp->query_vars['lost-password'])) { WC_Shortcode_My_Account::lost_password(); } else { wc_get_template('myaccount/form-login.php'); } echo '</div>'; } } }
/** * @deprecated */ function woocommerce_show_messages() { _deprecated_function('woocommerce_show_messages', '2.1', 'wc_print_notices'); wc_print_notices(); }
/** * Process the checkout after the confirm order button is pressed * * @access public * @return void */ public function process_checkout() { global $wpdb, $current_user; wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-process_checkout'); if (!defined('WOOCOMMERCE_CHECKOUT')) { define('WOOCOMMERCE_CHECKOUT', true); } // Prevent timeout @set_time_limit(0); do_action('woocommerce_before_checkout_process'); if (sizeof(WC()->cart->get_cart()) == 0) { wc_add_notice(sprintf(__('Sorry, your session has expired. <a href="%s" class="wc-backward">Return to homepage</a>', 'woocommerce'), home_url()), 'error'); } do_action('woocommerce_checkout_process'); // Checkout fields (not defined in checkout_fields) $this->posted['terms'] = isset($_POST['terms']) ? 1 : 0; $this->posted['createaccount'] = isset($_POST['createaccount']) ? 1 : 0; $this->posted['payment_method'] = isset($_POST['payment_method']) ? stripslashes($_POST['payment_method']) : ''; $this->posted['shipping_method'] = isset($_POST['shipping_method']) ? $_POST['shipping_method'] : ''; $this->posted['ship_to_different_address'] = isset($_POST['ship_to_different_address']) ? true : false; if (isset($_POST['shiptobilling'])) { _deprecated_argument('WC_Checkout::process_checkout()', '2.1', 'The "shiptobilling" field is deprecated. THe template files are out of date'); $this->posted['ship_to_different_address'] = $_POST['shiptobilling'] ? false : true; } // Ship to billing only option if (WC()->cart->ship_to_billing_address_only()) { $this->posted['ship_to_different_address'] = false; } // Update customer shipping and payment method to posted method $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); if (isset($this->posted['shipping_method']) && is_array($this->posted['shipping_method'])) { foreach ($this->posted['shipping_method'] as $i => $value) { $chosen_shipping_methods[$i] = wc_clean($value); } } WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); WC()->session->set('chosen_payment_method', $this->posted['payment_method']); // Note if we skip shipping $skipped_shipping = false; // Get posted checkout_fields and do validation foreach ($this->checkout_fields as $fieldset_key => $fieldset) { // Skip shipping if not needed if ($fieldset_key == 'shipping' && ($this->posted['ship_to_different_address'] == false || !WC()->cart->needs_shipping())) { $skipped_shipping = true; continue; } // Ship account if not needed if ($fieldset_key == 'account' && (is_user_logged_in() || $this->must_create_account == false && empty($this->posted['createaccount']))) { continue; } foreach ($fieldset as $key => $field) { if (!isset($field['type'])) { $field['type'] = 'text'; } // Get Value switch ($field['type']) { case "checkbox": $this->posted[$key] = isset($_POST[$key]) ? 1 : 0; break; case "multiselect": $this->posted[$key] = isset($_POST[$key]) ? implode(', ', array_map('wc_clean', $_POST[$key])) : ''; break; case "textarea": $this->posted[$key] = isset($_POST[$key]) ? wp_strip_all_tags(wp_check_invalid_utf8(stripslashes($_POST[$key]))) : ''; break; default: $this->posted[$key] = isset($_POST[$key]) ? wc_clean($_POST[$key]) : ''; break; } // Hooks to allow modification of value $this->posted[$key] = apply_filters('woocommerce_process_checkout_' . sanitize_title($field['type']) . '_field', $this->posted[$key]); $this->posted[$key] = apply_filters('woocommerce_process_checkout_field_' . $key, $this->posted[$key]); // Validation: Required fields if (isset($field['required']) && $field['required'] && empty($this->posted[$key])) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is a required field.', 'woocommerce'), 'error'); } if (!empty($this->posted[$key])) { // Validation rules if (!empty($field['validate']) && is_array($field['validate'])) { foreach ($field['validate'] as $rule) { switch ($rule) { case 'postcode': $this->posted[$key] = strtoupper(str_replace(' ', '', $this->posted[$key])); if (!WC_Validation::is_postcode($this->posted[$key], $_POST[$fieldset_key . '_country'])) { wc_add_notice(__('Please enter a valid postcode/ZIP.', 'woocommerce'), 'error'); } else { $this->posted[$key] = wc_format_postcode($this->posted[$key], $_POST[$fieldset_key . '_country']); } break; case 'phone': $this->posted[$key] = wc_format_phone_number($this->posted[$key]); if (!WC_Validation::is_phone($this->posted[$key])) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid phone number.', 'woocommerce'), 'error'); } break; case 'email': $this->posted[$key] = strtolower($this->posted[$key]); if (!is_email($this->posted[$key])) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid email address.', 'woocommerce'), 'error'); } break; case 'state': // Get valid states $valid_states = WC()->countries->get_states($_POST[$fieldset_key . '_country']); if ($valid_states) { $valid_state_values = array_flip(array_map('strtolower', $valid_states)); } // Convert value to key if set if (isset($valid_state_values[strtolower($this->posted[$key])])) { $this->posted[$key] = $valid_state_values[strtolower($this->posted[$key])]; } // Only validate if the country has specific state options if ($valid_states && sizeof($valid_states) > 0) { if (!in_array($this->posted[$key], array_keys($valid_states))) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not valid. Please enter one of the following:', 'woocommerce') . ' ' . implode(', ', $valid_states), 'error'); } } break; } } } } } } // Update customer location to posted location so we can correctly check available shipping methods if (isset($this->posted['billing_country'])) { WC()->customer->set_country($this->posted['billing_country']); } if (isset($this->posted['billing_state'])) { WC()->customer->set_state($this->posted['billing_state']); } if (isset($this->posted['billing_postcode'])) { WC()->customer->set_postcode($this->posted['billing_postcode']); } // Shipping Information if (!$skipped_shipping) { // Update customer location to posted location so we can correctly check available shipping methods if (isset($this->posted['shipping_country'])) { WC()->customer->set_shipping_country($this->posted['shipping_country']); } if (isset($this->posted['shipping_state'])) { WC()->customer->set_shipping_state($this->posted['shipping_state']); } if (isset($this->posted['shipping_postcode'])) { WC()->customer->set_shipping_postcode($this->posted['shipping_postcode']); } } else { // Update customer location to posted location so we can correctly check available shipping methods if (isset($this->posted['billing_country'])) { WC()->customer->set_shipping_country($this->posted['billing_country']); } if (isset($this->posted['billing_state'])) { WC()->customer->set_shipping_state($this->posted['billing_state']); } if (isset($this->posted['billing_postcode'])) { WC()->customer->set_shipping_postcode($this->posted['billing_postcode']); } } // Update cart totals now we have customer address WC()->cart->calculate_totals(); // Terms if (!isset($_POST['woocommerce_checkout_update_totals']) && empty($this->posted['terms']) && wc_get_page_id('terms') > 0) { wc_add_notice(__('You must accept our Terms & Conditions.', 'woocommerce'), 'error'); } if (WC()->cart->needs_shipping()) { if (!in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { wc_add_notice(sprintf(__('Unfortunately <strong>we do not ship to %s</strong>. Please enter an alternative shipping address.', 'woocommerce'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()), 'error'); } // Validate Shipping Methods $packages = WC()->shipping->get_packages(); $this->shipping_methods = WC()->session->get('chosen_shipping_methods'); foreach ($packages as $i => $package) { if (!isset($package['rates'][$this->shipping_methods[$i]])) { wc_add_notice(__('Invalid shipping method.', 'woocommerce'), 'error'); $this->shipping_methods[$i] = ''; } } } if (WC()->cart->needs_payment()) { // Payment Method $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); if (!isset($available_gateways[$this->posted['payment_method']])) { $this->payment_method = ''; wc_add_notice(__('Invalid payment method.', 'woocommerce'), 'error'); } else { $this->payment_method = $available_gateways[$this->posted['payment_method']]; $this->payment_method->validate_fields(); } } // Action after validation do_action('woocommerce_after_checkout_validation', $this->posted); if (!isset($_POST['woocommerce_checkout_update_totals']) && wc_notice_count('error') == 0) { try { // Customer accounts $this->customer_id = apply_filters('woocommerce_checkout_customer_id', get_current_user_id()); if (!is_user_logged_in() && ($this->must_create_account || !empty($this->posted['createaccount']))) { $username = !empty($this->posted['account_username']) ? $this->posted['account_username'] : ''; $password = !empty($this->posted['account_password']) ? $this->posted['account_password'] : ''; $new_customer = wc_create_new_customer($this->posted['billing_email'], $username, $password); if (is_wp_error($new_customer)) { throw new Exception($new_customer->get_error_message()); } $this->customer_id = $new_customer; wc_set_customer_auth_cookie($this->customer_id); // As we are now logged in, checkout will need to refresh to show logged in data WC()->session->set('reload_checkout', true); // Add customer info from other billing fields if ($this->posted['billing_first_name'] && apply_filters('woocommerce_checkout_update_customer_data', true, $this)) { $userdata = array('ID' => $this->customer_id, 'first_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : '', 'last_name' => $this->posted['billing_last_name'] ? $this->posted['billing_last_name'] : '', 'display_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : ''); wp_update_user(apply_filters('woocommerce_checkout_customer_userdata', $userdata, $this)); } } // Do a final stock check at this point $this->check_cart_items(); // Abort if errors are present if (wc_notice_count('error') > 0) { throw new Exception(); } $order_id = $this->create_order(); do_action('woocommerce_checkout_order_processed', $order_id, $this->posted); // Process payment if (WC()->cart->needs_payment()) { // Store Order ID in session so it can be re-used after payment failure WC()->session->order_awaiting_payment = $order_id; // Process Payment $result = $available_gateways[$this->posted['payment_method']]->process_payment($order_id); // Redirect to success/confirmation/payment page if ($result['result'] == 'success') { $result = apply_filters('woocommerce_payment_successful_result', $result, $order_id); if (is_ajax()) { echo '<!--WC_START-->' . json_encode($result) . '<!--WC_END-->'; exit; } else { wp_redirect($result['redirect']); exit; } } } else { if (empty($order)) { $order = new WC_Order($order_id); } // No payment was required for order $order->payment_complete(); // Empty the Cart WC()->cart->empty_cart(); // Get redirect $return_url = $order->get_checkout_order_received_url(); // Redirect to success/confirmation/payment page if (is_ajax()) { echo '<!--WC_START-->' . json_encode(array('result' => 'success', 'redirect' => apply_filters('woocommerce_checkout_no_payment_needed_redirect', $return_url, $order))) . '<!--WC_END-->'; exit; } else { wp_safe_redirect(apply_filters('woocommerce_checkout_no_payment_needed_redirect', $return_url, $order)); exit; } } } catch (Exception $e) { if (!empty($e)) { wc_add_notice($e->getMessage(), 'error'); } } } // endif // If we reached this point then there were errors if (is_ajax()) { ob_start(); wc_print_notices(); $messages = ob_get_clean(); echo '<!--WC_START-->' . json_encode(array('result' => 'failure', 'messages' => $messages, 'refresh' => isset(WC()->session->refresh_totals) ? 'true' : 'false', 'reload' => isset(WC()->session->reload_checkout) ? 'true' : 'false')) . '<!--WC_END-->'; unset(WC()->session->refresh_totals, WC()->session->reload_checkout); exit; } }
/** * If checkout failed during an AJAX call, send failure response. */ protected function send_ajax_failure_response() { if (is_ajax()) { // only print notices if not reloading the checkout, otherwise they're lost in the page reload if (!isset(WC()->session->reload_checkout)) { ob_start(); wc_print_notices(); $messages = ob_get_clean(); } $response = array('result' => 'failure', 'messages' => isset($messages) ? $messages : '', 'refresh' => isset(WC()->session->refresh_totals), 'reload' => isset(WC()->session->reload_checkout)); unset(WC()->session->refresh_totals, WC()->session->reload_checkout); wp_send_json($response); } }
/** * Checks revocation form and sends Email to customer and Admin */ public static function gzd_revocation() { check_ajax_referer('woocommerce-revocation', 'security'); wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-revocation'); $data = array(); $fields = WC_GZD_Revocation::get_fields(); if (!empty($fields)) { foreach ($fields as $key => $field) { if ($key != 'sep') { if ($key == 'address_mail') { if (!is_email($_POST[$key])) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . _x('is not a valid email address.', 'revocation-form', 'woocommerce-germanized'), 'error'); } } elseif ($key == 'address_postal') { if (!WC_Validation::is_postcode($_POST[$key], $_POST['address_country']) || empty($_POST[$key])) { wc_add_notice(_x('Please enter a valid postcode/ZIP', 'revocation-form', 'woocommerce-germanized'), 'error'); } } else { if (isset($field['required']) && empty($_POST[$key])) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . _x('is not valid.', 'revocation-form', 'woocommerce-germanized'), 'error'); } } if (!empty($_POST[$key])) { if ($field['type'] == 'country') { $countries = WC()->countries->get_countries(); $data[$key] = $countries[sanitize_text_field($_POST[$key])]; } else { $data[$key] = sanitize_text_field($_POST[$key]); } } } } } $error = false; if (wc_notice_count('error') == 0) { wc_add_notice(_x('Thank you. We have received your Revocation Request. You will receive a conformation email within a few minutes.', 'revocation-form', 'woocommerce-germanized'), 'success'); // Send Mail $mails = WC()->mailer()->get_emails(); if (!empty($mails)) { foreach ($mails as $mail) { if ($mail->id == 'customer_revocation') { $mail->trigger($data); // Send to Admin $data['mail'] = get_bloginfo('admin_email'); $mail->trigger($data); } } } } else { $error = true; } ob_start(); wc_print_notices(); $messages = ob_get_clean(); if ($error) { echo '<!--WC_START-->' . json_encode(array('result' => 'failure', 'messages' => isset($messages) ? $messages : '')) . '<!--WC_END-->'; } else { if (is_ajax()) { echo '<!--WC_START-->' . json_encode(array('result' => 'success', 'messages' => isset($messages) ? $messages : '')) . '<!--WC_END-->'; } } exit; }
/** * Show the checkout */ private static function checkout() { // Show non-cart errors wc_print_notices(); // Check cart has contents if (sizeof(WC()->cart->get_cart()) == 0) { return; } // Check cart contents for errors do_action('woocommerce_check_cart_items'); // Calc totals WC()->cart->calculate_totals(); // Get checkout object $checkout = WC()->checkout(); if (empty($_POST) && wc_notice_count('error') > 0) { wc_get_template('checkout/cart-errors.php', array('checkout' => $checkout)); } else { $non_js_checkout = !empty($_POST['woocommerce_checkout_update_totals']) ? true : false; if (wc_notice_count('error') == 0 && $non_js_checkout) { wc_add_notice(__('The order totals have been updated. Please confirm your order by pressing the Place Order button at the bottom of the page.', 'woocommerce')); } wc_get_template('checkout/form-checkout.php', array('checkout' => $checkout)); } }
function WooComposer_Carousel($atts) { $product_style = $slides_to_scroll = $scroll_speed = $advanced_opts = $output = $autoplay_speed = $scroll_opts = ''; extract(shortcode_atts(array("product_style" => "style01", "slides_to_scroll" => "1", "scroll_speed" => "1000", "advanced_opts" => "infinite", "autoplay_speed" => "500", "scroll_opts" => "auto"), $atts)); $infinite = $autoplay = $dots = 'false'; $advanced_opts = explode(",", $advanced_opts); if (in_array("infinite", $advanced_opts)) { $infinite = 'true'; } if (in_array("autoplay", $advanced_opts)) { $autoplay = 'true'; } if (in_array("dots", $advanced_opts)) { $dots = 'true'; } ob_start(); $output .= '<div class="woocommerce">'; if (function_exists('wc_print_notices')) { wc_print_notices(); } $output .= ob_get_clean(); $output .= '</div>'; $uid = uniqid(); $output .= '<div id="woo-carousel-' . $uid . '" class="woocomposer_carousel">'; $template = 'design-loop-' . $product_style . '.php'; require_once $template; $function = 'WooComposer_Loop_' . $product_style; $output .= $function($atts, 'carousel'); $output .= '</div>'; $output .= '<script> jQuery(document).ready(function(){ var columns = jQuery("#woo-carousel-' . $uid . ' > .woocomposer").data("columns"); var slides_scroll_opt = "' . $scroll_opts . '"; var slides_to_scroll; if(slides_scroll_opt == "custom"){ slides_to_scroll = ' . $slides_to_scroll . '; } else { slides_to_scroll = columns; } var inline_vc = jQuery(".woocomposer_carousel").find(".wcmp_vc_inline").length; if(inline_vc == 0){ jQuery("#woo-carousel-' . $uid . ' > .woocomposer").slick({ infinite: ' . $infinite . ', slidesToShow: columns, slidesToScroll: slides_to_scroll, speed: ' . $scroll_speed . ', dots: ' . $dots . ', autoplay: ' . $autoplay . ', autoplaySpeed: ' . $autoplay_speed . ', responsive: [{ breakpoint: 1024, settings: { slidesToShow: 3, slidesToScroll: 3, infinite: true, dots: true } }, { breakpoint: 600, settings: { slidesToShow: 2, slidesToScroll: 2 } }, { breakpoint: 480, settings: { slidesToShow: 1, slidesToScroll: 1 } }] }); } var carousel_set = "{infinite: ' . $infinite . ',\\ slidesToShow: columns,\\ slidesToScroll: slides_to_scroll,\\ speed: ' . $scroll_speed . ',\\ dots: ' . $dots . ',\\ autoplay: ' . $autoplay . ',\\ autoplaySpeed: ' . $autoplay_speed . ',\\ responsive: [{\\ breakpoint: 1024,\\ settings: {\\ slidesToShow: 3,\\ slidesToScroll: 3,\\ infinite: true,\\ dots: true\\ }\\ }, {\\ breakpoint: 600,\\ settings: {\\ slidesToShow: 2,\\ slidesToScroll: 2\\ }\\ }, {\\ breakpoint: 480,\\ settings: {\\ slidesToShow: 1,\\ slidesToScroll: 1\\ }\\ }]\\ });}"; jQuery("#woo-carousel-' . $uid . '").attr("data-slick", carousel_set); }); jQuery(window).load(function(){ //jQuery("[data-save=true]").trigger("click"); }); </script>'; return $output; }
/** * Test wc_print_notices(). * * @since 2.2 */ public function test_wc_print_notices() { wc_add_notice('One True Notice', 'notice'); $this->expectOutputString('<div class="woocommerce-info">One True Notice</div>'); wc_print_notices(); $this->assertEmpty(WC()->session->get('wc_notices')); }
/** * Outputs the pay page - payment gateways can hook in here to show payment forms etc **/ function woocommerce_review_order_angelleye() { global $woocommerce; //$woocommerce->nocache(); wc_print_notices(); echo "\n\t\t\t<script>\n\t\t\tjQuery(document).ready(function(\$) {\n\t\t\t\t// Inputs/selects which update totals instantly\n \$('form.checkout').unbind( 'submit' );\n\t\t\t});\n\t\t\t</script>\n\t\t\t"; //echo '<form class="checkout" method="POST" action="' . add_query_arg( 'pp_action', 'payaction', add_query_arg( 'wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url( '/' ) ) ) . '">'; $template = plugin_dir_path(__FILE__) . 'template/'; //Allow override in theme: <theme_name>/woocommerce/paypal-paypal-review-order.php wc_get_template('paypal-review-order.php', array(), '', $template); do_action('woocommerce_ppe_checkout_order_review'); //echo '<p><a class="button cancel" href="' . $woocommerce->cart->get_cart_url() . '">'.__('Cancel order', 'paypal-for-woocommerce').'</a> '; //echo '<input type="submit" class="button" value="' . __( 'Place Order','paypal-for-woocommerce') . '" /></p>'; //echo '</form>'; }
function displayForm($atts) { $user_status = is_user_logged_in(); if (!$user_status && !isset($_GET['action'])) { ?> <div id="WK_ContentLoginForm"> <?php wc_print_notices(); ?> <form method="post" class="login"> <fieldset class="[ margin-bottom ]"> <label for="username"><?php _e('Username or email address', 'marketplace'); ?> <span class="required">*</span></label> <input type="text" class="[ input-text ][ xmall-12 ]" name="wkmp_username" id="username" value="<?php echo isset($_GET['email']) ? $_GET['email'] : ''; ?> " placeholder="enter your email id or username"/> </fieldset> <fieldset class="[ margin-bottom ]"> <label for="password"><?php _e('Password', 'marketplace'); ?> <span class="required">*</span></label> <input class="[ input-text ][ xmall-12 ]" type="password" name="password" id="password" value="" placeholder="enter your password" /> </fieldset> <fieldset> <input type="hidden" value="<?php echo wp_get_referer(); ?> " name="_wp_http_referer1"> </fieldset> <fieldset class="[ margin-bottom ]"> <label for="rememberme"> <input name="rememberme" type="checkbox" id="rememberme" value="forever" /> <?php _e('Remember me', 'marketplace'); ?> </label> </fieldset> <fieldset class="[ text-center ][ margin-bottom "> <?php wp_nonce_field('marketplace-username'); ?> <input type="submit" class="[ button button--primary ]" name="login" value="<?php _e('Login', 'marketplace'); ?> " /> <a href="<?php echo wp_registration_url(); ?> "><input type="button" class="[ button button--primary ]" value="<?php _e("Register"); ?> "></a> </fieldset> <fieldset class="[ text-center ]"> <a href="<?php echo esc_url(wc_lostpassword_url()); ?> "><?php _e('Lost your password?', 'marketplace'); ?> </a> </fieldset> </form> </div> <!-- content div --> <?php } else { if ($user_status) { global $wpdb; $wpmp_obj1 = new MP_Form_Handler(); $current_user = wp_get_current_user(); // MP_Form_Handler::profile_edit_redirection(); $wpmp_obj1->profile_edit_redirection(); // $avatar=MP_Form_Handler::get_user_avatar($current_user->ID,'avatar'); $avatar = $wpmp_obj1->get_user_avatar($current_user->ID, 'avatar'); // $seller_detail=MP_Form_Handler::seller_details($current_user->ID); $seller_detail = $wpmp_obj1->seller_details($current_user->ID); $seller_info = $wpdb->get_var("SELECT user_id FROM {$wpdb->prefix}mpsellerinfo WHERE user_id = '" . $current_user->data->ID . "' and seller_value=1"); echo '<h3 class="[ text-center ]"><small>Profile</small></h3>'; echo '<div class="wk_profileclass">'; echo '<form method="post">'; if ($current_user->data->ID && $seller_info > 0) { if (isset($avatar[0]->meta_value)) { echo '<div class="wk_profileimg"><img src="' . content_url() . '/uploads/' . $avatar[0]->meta_value . '" /></div>'; } else { echo '<div class="wk_profileimg"><img src="' . content_url() . '/plugins/marketplace/assets/images/genric-male.png" /></div>'; } } echo '<div class="wk_profileinfo"><div class="wk_profiledata"><label>Username </label> : ' . $current_user->user_login . '</div>'; echo '<div class="wk_profiledata"><label>E-mail </label> : ' . $current_user->user_email . '</div>'; echo '<div class="wk_profiledata"><label>Name </label> : ' . $current_user->user_firstname . ' ' . $current_user->user_lastname . '</div>'; echo '<div class="wk_profiledata"><label>Display name </label> : ' . $current_user->display_name . '</div>'; if ($current_user->data->ID && $seller_info > 0) { echo '<div class="wk_profiledata"><label>Shop Name </label> : ' . $seller_detail['shop_name'][0] . '</div>'; echo '<div class="wk_profiledata"><label>Address </label> : ' . $seller_detail['shop_address'][0] . '</div>'; if (strchr(get_permalink(), '?')) { $icon = '&'; } else { $icon = '?'; } echo '<div class="wk_profile_btn"><a href="' . get_permalink() . $icon . 'page=pedit" title="Edit Profile" class="[ button button--highlight ]">Edit</a></div>'; } //echo '<a href="'.wp_logout_url().'" title="Logout" class="button">Logout</a><br /></div>'; echo '</form></div> </div>'; } else { if (isset($_GET['action']) && !$user_status && $_GET['action'] == 'mp_register') { ?> <div id="WK_ContentRegisterForm"> <?php wc_print_notices(); ?> <h3 class="[ text-center ][ margin-bottom ]"><small>Registrate</h3></small> <form action="<?php echo get_permalink(); ?> " method="post" id="registration_form"> <div class="[ wk_login_input ][ ]"> <label for="wk_username"><?php _e("Username"); ?> </label><span class="required">*</span> <input type="text" name="wk_username" placeholder="" id="wk_username" class="[ wk_loginput ][ xmall-12 ]"/> <div class="error-class" id="seller_user_name"></div> </div> <div class="[ wk_login_input ][ ]"> <label for="wk_firstname">Nombre</label><span class="required">*</span> <input type="text" placeholder="" name="wk_firstname" id="wk_firstname" class="[ wk_loginput ][ xmall-12 ]"/> <div class="error-class" id="seller_first_name"></div> </div> <div class="[ wk_login_input ][ ]"> <label for="wk_lastname">Apellido</label><span class="required">*</span> <input type="text" placeholder="" name="wk_lastname" id="wk_lastname" class="[ wk_loginput ][ xmall-12 ]"/> <div class="error-class" id="seller_last_name"></div> </div> <div class="[ wk_login_input ][ ]"> <label for="wk_useremail"><?php _e("E-mail"); ?> </label><span class="required">*</span> <input type="text" placeholder="" name="wk_useremail" id="wk_useremail" class="[ wk_loginput ][ xmall-12 ]"/> <div class="error-class" id="seller_email"></div> </div> <div id="add_sller_shop"></div> <div class="[ wk_login_input ][ ]"> <label for="wk_userseller" name="user_email" class="wk_regis"><?php _e("Want To Become A Seller"); ?> </label><span class="required">*</span> <input type="radio" name="selleraccess" value="1" class="wk_userseller"> <?php _e("Yes"); ?>   <input type="radio" name="selleraccess" value="0" class="wk_userseller"> <?php _e("No"); ?> <div class="error-class" id="select-seller_access"></div> </div> <?php apply_filters('register_url', 'seller registration'); ?> <div class="[ wk_login_input ][ ]"> <div><img src="<?php echo plugins_url(); ?> /marketplace/includes/front/my-image.php" id="wk_captcha_image"></div> <label for="wk_captcha">Escribe el texto del captcha:</label> <input class="[ xmall-12 ]" type="text" name="wk_captcha" id="wk_captcha"> <input type="hidden" id="wk_captcha_result" name="wk_captcha_result" value="0"> <div class="error-class" id="wk_captcha_error"></div> <div class="correct-class" id="wk_captcha_correct"></div> </div> <div class="[ text-center ]"> <input type="submit" value="Register" class="[ button button--primary ][ ]" name="register_submit" id="register_submit"/> <a style="text-decoration: none;" href="<?php echo get_permalink(); ?> "> <input class="[ button button--primary ][ ]" type="button" value="<?php _e("Login"); ?> "> </a> </div> </form> </div> <?php } else { if (isset($_GET['action']) && !$user_status && $_GET['action'] == 'lostpassword') { ?> <section id="contentForm"> <form name="lostpasswordform" id="lostpasswordform" action="" method="post"> <!--<h1>Reset</h1>--> <div> <input type="text" name="user_login" id="user_login" placeholder="Username or E-mail" value="" required="" size="20" tabindex="10"> </div> <div> <input type="hidden" name="redirect_to" value="<?php echo get_permalink(); ?> "> <input type="submit" name="wp-submit" id="wp-submit" class="button-primary" value="Get Password" tabindex="100"> <a href="<?php echo get_permalink(); ?> ">Login Now</a> </div> </form> </section> <?php } } } } }
/** * Show the add payment method page */ private static function add_payment_method() { if (!is_user_logged_in()) { wp_safe_redirect(wc_get_page_permalink('myaccount')); exit; } else { do_action('before_woocommerce_add_payment_method'); wc_add_notice(__('Add a new payment method.', 'woocommerce'), 'notice'); wc_print_notices(); // Add payment method form wc_get_template('myaccount/form-add-payment-method.php'); wc_print_notices(); do_action('after_woocommerce_add_payment_method'); } }
/** * [wcv_vendor_dashboard] shortcode * * @param array $atts * * @return unknown */ public function display_vendor_products($atts) { global $start_date, $end_date; $start_date = !empty($_SESSION['PV_Session']['start_date']) ? $_SESSION['PV_Session']['start_date'] : strtotime(date('Ymd', strtotime(date('Ym', current_time('timestamp')) . '01'))); $end_date = !empty($_SESSION['PV_Session']['end_date']) ? $_SESSION['PV_Session']['end_date'] : strtotime(date('Ymd', current_time('timestamp'))); $can_view_orders = WC_Vendors::$pv_options->get_option('can_show_orders'); $settings_page = get_permalink(WC_Vendors::$pv_options->get_option('shop_settings_page')); $can_submit = WC_Vendors::$pv_options->get_option('can_submit_products'); $submit_link = $can_submit ? admin_url('post-new.php?post_type=product') : ''; $edit_link = $can_submit ? admin_url('edit.php?post_type=product') : ''; if (!$this->can_view_vendor_page()) { return false; } extract(shortcode_atts(array('user_id' => get_current_user_id(), 'datepicker' => true), $atts)); $vendor_products = WCV_Queries::get_commission_products($user_id); $products = array(); foreach ($vendor_products as $_product) { $products[] = $_product->ID; } $vendor_summary = $this->format_product_details($vendor_products); $order_summary = WCV_Queries::get_orders_for_products($products); $shop_page = WCV_Vendors::get_vendor_shop_page(wp_get_current_user()->user_login); wp_enqueue_style('wcv_frontend_style', wcv_assets_url . 'css/wcv-frontend.css'); $providers = array(); $provider_array = array(); // WC Shipment Tracking Providers if (class_exists('WC_Shipment_Tracking')) { $WC_Shipment_Tracking = new WC_Shipment_Tracking(); $providers = method_exists($WC_Shipment_Tracking, 'get_providers') ? $WC_Shipment_Tracking->get_providers() : $WC_Shipment_Tracking->providers; $provider_array = array(); foreach ($providers as $all_providers) { foreach ($all_providers as $provider => $format) { $provider_array[sanitize_title($provider)] = urlencode($format); } } } ob_start(); do_action('wcvendors_before_dashboard'); wc_print_notices(); wc_get_template('links.php', array('shop_page' => urldecode($shop_page), 'settings_page' => $settings_page, 'can_submit' => $can_submit, 'submit_link' => $submit_link, 'edit_link' => $edit_link), 'wc-vendors/dashboard/', wcv_plugin_dir . 'templates/dashboard/'); if ($can_view_sales = WC_Vendors::$pv_options->get_option('can_view_frontend_reports')) { wc_get_template('reports.php', array('start_date' => $start_date, 'end_date' => $end_date, 'vendor_products' => $vendor_products, 'vendor_summary' => $vendor_summary, 'datepicker' => $datepicker, 'can_view_orders' => $can_view_orders), 'wc-vendors/dashboard/', wcv_plugin_dir . 'templates/dashboard/'); } wc_get_template('orders.php', array('start_date' => $start_date, 'end_date' => $end_date, 'vendor_products' => $vendor_products, 'order_summary' => $order_summary, 'datepicker' => $datepicker, 'providers' => $providers, 'provider_array' => $provider_array, 'can_view_orders' => $can_view_orders), 'wc-vendors/dashboard/', wcv_plugin_dir . 'templates/dashboard/'); do_action('wcvendors_after_dashboard'); if (function_exists('wc_enqueue_js')) { wc_enqueue_js(WCV_Vendor_dashboard::wc_st_js($provider_array)); } else { $woocommerce->add_inline_js($js); } return ob_get_clean(); }
/** * Prints wc notice for wishlist pages * * @return void * @since 2.0.5 */ public function print_notices() { global $woocommerce; // Start wishlist page printing if (function_exists('wc_print_notices')) { wc_print_notices(); } elseif (method_exists($woocommerce, 'show_message')) { $woocommerce->show_messages(); } }
/** * Prints messages and errors which are stored in the session, then clears them. * * @since 1.0 */ public static function wc_print_notices() { if (self::is_wc_version_gte_2_1()) { wc_print_notices(); } else { global $woocommerce; $woocommerce->show_messages(); } }
<?php /** * Cart errors page * * @author WooThemes * @package WooCommerce/Templates * @version 1.6.4 */ ?> <?php wc_print_notices(); ?> <p><?php _e('There are some issues with the items in your cart (shown above). Please go back to the cart page and resolve these issues before checking out.', 'yit') ?></p> <?php do_action('woocommerce_cart_has_errors'); ?> <p><a class="button" href="<?php echo get_permalink(wc_get_page_id('cart')); ?>"><?php _e('← Return To Cart', 'yit') ?></a></p>
public function wcviews_add_to_cart_success_html() { $check_if_using_revised_wc = $this->wcviews_using_woocommerce_two_point_one_above(); //Has message defined //Can be reordered anywhere ob_start(); if (is_product()) { do_action('woocommerce_before_single_product'); } else { //https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/193583262/comments#comment_303204369 if ($check_if_using_revised_wc) { //Using revised WC //Use wc_print_notices() wc_print_notices(); } else { //Old WC, backward compatibility woocommerce_show_messages(); } } $add_to_cart_success_content = ob_get_contents(); ob_end_clean(); return $add_to_cart_success_content; }
<?php /** * Cart Page * * @author WooThemes * @package WooCommerce/Templates * @version 2.3.8 */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly } defender_print_page_heading(); wc_print_notices(); ?> <?php do_action('woocommerce_before_cart'); ?> <section id="wc-cart"> <div class="ui page grid"> <div class="centered row"> <div class="column"> <form action="<?php echo esc_url(WC()->cart->get_cart_url()); ?> " method="post">
/** * @deprecated 2.1.0 */ public function show_messages() { _deprecated_function('Woocommerce->show_messages', '2.1', 'wc_print_notices()'); wc_print_notices(); }