Exemplo n.º 1
0
 /**
  * API request - Trigger any API requests.
  *
  * @since   2.0
  * @version 2.4
  */
 public function handle_api_requests()
 {
     global $wp;
     if (!empty($_GET['wc-api'])) {
         $wp->query_vars['wc-api'] = $_GET['wc-api'];
     }
     // wc-api endpoint requests.
     if (!empty($wp->query_vars['wc-api'])) {
         // Buffer, we won't want any output here.
         ob_start();
         // No cache headers.
         nocache_headers();
         // Clean the API request.
         $api_request = strtolower(wc_clean($wp->query_vars['wc-api']));
         // Trigger generic action before request hook.
         do_action('woocommerce_api_request', $api_request);
         // Is there actually something hooked into this API request? If not trigger 400 - Bad request.
         status_header(has_action('woocommerce_api_' . $api_request) ? 200 : 400);
         // Trigger an action which plugins can hook into to fulfill the request.
         do_action('woocommerce_api_' . $api_request);
         // Done, clear buffer and exit.
         ob_end_clean();
         die('-1');
     }
 }
 /**
  * Output the calendar view
  */
 public function output()
 {
     wp_enqueue_script('chosen');
     $product_filter = isset($_REQUEST['filter_bookings']) ? absint($_REQUEST['filter_bookings']) : '';
     $view = isset($_REQUEST['view']) && $_REQUEST['view'] == 'day' ? 'day' : 'month';
     if ($view == 'day') {
         $day = isset($_REQUEST['calendar_day']) ? wc_clean($_REQUEST['calendar_day']) : date('Y-m-d');
         $this->bookings = WC_Bookings_Controller::get_bookings_in_date_range(strtotime('midnight', strtotime($day)), strtotime('midnight +1 day', strtotime($day)), $product_filter);
     } else {
         $month = isset($_REQUEST['calendar_month']) ? absint($_REQUEST['calendar_month']) : date('n');
         $year = isset($_REQUEST['calendar_year']) ? absint($_REQUEST['calendar_year']) : date('Y');
         if ($year < date('Y') - 10 || $year > 2100) {
             $year = date('Y');
         }
         if ($month > 12) {
             $month = 1;
             $year++;
         }
         if ($month < 1) {
             $month = 1;
             $year--;
         }
         $start_week = (int) date('W', strtotime("first day of {$year}-{$month}"));
         $end_week = (int) date('W', strtotime("last day of {$year}-{$month}"));
         if ($end_week == 1) {
             $end_week = 53;
         }
         $this->bookings = WC_Bookings_Controller::get_bookings_in_date_range(strtotime($year . 'W' . str_pad($start_week, 2, '0', STR_PAD_LEFT)), strtotime($year . 'W' . str_pad($end_week + 1, 2, '0', STR_PAD_LEFT)), $product_filter);
     }
     include 'views/html-calendar-' . $view . '.php';
     wc_enqueue_js('$( "select#calendar-bookings-filter" ).chosen();');
 }
 /**
  * Get the new payment data from POST and check the new payment method supports
  * the new admin change hook.
  *
  * @since 2.0
  * @param $subscription WC_Subscription
  */
 public static function save_meta($subscription)
 {
     if (empty($_POST['_wcsnonce']) || !wp_verify_nonce($_POST['_wcsnonce'], 'wcs_change_payment_method_admin')) {
         return;
     }
     $payment_gateways = WC()->payment_gateways->payment_gateways();
     $payment_method = isset($_POST['_payment_method']) ? wc_clean($_POST['_payment_method']) : '';
     $payment_method_meta = apply_filters('woocommerce_subscription_payment_meta', array(), $subscription);
     $payment_method_meta = !empty($payment_method_meta[$payment_method]) ? $payment_method_meta[$payment_method] : array();
     $valid_payment_methods = self::get_valid_payment_methods($subscription);
     if (!isset($valid_payment_methods[$payment_method])) {
         throw new Exception(__('Please choose a valid payment gateway to change to.', 'woocommerce-subscriptions'));
     }
     if (!empty($payment_method_meta)) {
         foreach ($payment_method_meta as $meta_table => &$meta) {
             if (!is_array($meta)) {
                 continue;
             }
             foreach ($meta as $meta_key => &$meta_data) {
                 $meta_data['value'] = isset($_POST['_payment_method_meta'][$meta_table][$meta_key]) ? $_POST['_payment_method_meta'][$meta_table][$meta_key] : '';
             }
         }
     }
     $payment_gateway = 'manual' != $payment_method ? $payment_gateways[$payment_method] : '';
     if (!$subscription->is_manual() && property_exists($subscription->payment_gateway, 'id') && ('' == $payment_gateway || $subscription->payment_gateway->id != $payment_gateway->id)) {
         // Before updating to a new payment gateway make sure the subscription status is updated with the current gateway
         $gateway_status = apply_filters('wcs_gateway_status_payment_changed', 'cancelled', $subscription, $payment_gateway);
         WC_Subscriptions_Payment_Gateways::trigger_gateway_status_updated_hook($subscription, $gateway_status);
     }
     $subscription->set_payment_method($payment_gateway, $payment_method_meta);
 }
 /**
  * Check Response for PDT
  */
 public function check_response()
 {
     if (empty($_REQUEST['cm']) || empty($_REQUEST['tx']) || empty($_REQUEST['st'])) {
         return;
     }
     $order_id = wc_clean(stripslashes($_REQUEST['cm']));
     $status = wc_clean(strtolower(stripslashes($_REQUEST['st'])));
     $amount = wc_clean(stripslashes($_REQUEST['amt']));
     $transaction = wc_clean(stripslashes($_REQUEST['tx']));
     if (!($order = $this->get_paypal_order($order_id)) || !$order->has_status('pending')) {
         return false;
     }
     if ($this->validate_transaction($transaction) && 'completed' === $status) {
         if ($order->get_total() != $amount) {
             WC_Gateway_Paypal::log('Payment error: Amounts do not match (amt ' . $amount . ')');
             $this->payment_on_hold($order, sprintf(__('Validation error: PayPal amounts do not match (amt %s).', 'woocommerce'), $amount));
         } else {
             $this->payment_complete($order, $transaction, __('PDT payment completed', 'woocommerce'));
             if (!empty($_REQUEST['mc_fee'])) {
                 // log paypal transaction fee
                 update_post_meta($order->id, 'PayPal Transaction Fee', wc_clean($_REQUEST['mc_fee']));
             }
         }
     }
 }
 /**
  * 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');
         }
     }
 }
 /**
  * Constructor.
  *
  * @return \YITH_WCStripe_Gateway
  * @since 1.0.0
  */
 public function __construct()
 {
     $this->id = YITH_WCStripe::$gateway_id;
     $this->has_fields = true;
     $this->method_title = apply_filters('yith_stripe_method_title', __('Stripe', 'yith-stripe'));
     $this->method_description = apply_filters('yith_stripe_method_description', __('Take payments via Stripe - uses stripe.js to create card tokens and the Stripe SDK. Requires SSL when sandbox is disabled.', 'yith-stripe'));
     $this->supports = array('products');
     $this->instance = preg_replace('/http(s)?:\\/\\//', '', site_url());
     // Load the settings.
     $this->init_form_fields();
     $this->init_settings();
     // Define user set variables
     $this->title = $this->get_option('title');
     $this->description = $this->get_option('description');
     $this->env = $this->get_option('enabled_test_mode') == 'yes' ? 'test' : 'live';
     $this->private_key = $this->get_option($this->env . '_secrect_key');
     $this->public_key = $this->get_option($this->env . '_publishable_key');
     $this->modal_image = $this->get_option('modal_image');
     $this->mode = 'hosted';
     // post data
     $this->token = isset($_POST['stripe_token']) ? wc_clean($_POST['stripe_token']) : '';
     // save
     add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
     // others
     add_action('admin_notices', array($this, 'admin_notices'));
     add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));
     add_action('woocommerce_api_' . strtolower(get_class($this)), array($this, 'return_handler'));
 }
 /**
  * Get the new payment data from POST and check the new payment method supports
  * the new admin change hook.
  *
  * @since 2.0
  * @param $subscription WC_Subscription
  */
 public static function save_meta($subscription)
 {
     if (empty($_POST['_wcsnonce']) || !wp_verify_nonce($_POST['_wcsnonce'], 'wcs_change_payment_method_admin')) {
         return;
     }
     $payment_gateways = WC()->payment_gateways->payment_gateways();
     $payment_method = isset($_POST['_payment_method']) ? wc_clean($_POST['_payment_method']) : '';
     $payment_method_meta = apply_filters('woocommerce_subscription_payment_meta', array(), $subscription);
     $payment_method_meta = !empty($payment_method_meta[$payment_method]) ? $payment_method_meta[$payment_method] : array();
     $valid_payment_methods = self::get_valid_payment_methods($subscription);
     if (!isset($valid_payment_methods[$payment_method])) {
         throw new Exception(__('Please choose a valid payment gateway to change to.', 'woocommerce-subscriptions'));
     }
     if (!empty($payment_method_meta)) {
         foreach ($payment_method_meta as $meta_table => &$meta) {
             if (!is_array($meta)) {
                 continue;
             }
             foreach ($meta as $meta_key => &$meta_data) {
                 $meta_data['value'] = isset($_POST['_payment_method_meta'][$meta_table][$meta_key]) ? $_POST['_payment_method_meta'][$meta_table][$meta_key] : '';
             }
         }
     }
     $payment_gateway = 'manual' != $payment_method ? $payment_gateways[$payment_method] : '';
     $subscription->set_payment_method($payment_gateway, $payment_method_meta);
 }
Exemplo n.º 8
0
 public static function gzd_json_search_delivery_time()
 {
     ob_start();
     check_ajax_referer('search-products', 'security');
     $term = (string) wc_clean(stripslashes($_GET['term']));
     $terms = array();
     if (empty($term)) {
         die;
     }
     $args = array('hide_empty' => false);
     if (is_numeric($term)) {
         $args['include'] = array(absint($term));
     } else {
         $args['name__like'] = (string) $term;
     }
     $query = get_terms('product_delivery_time', $args);
     if (!empty($query)) {
         foreach ($query as $term) {
             $terms[$term->term_id] = rawurldecode($term->name);
         }
     } else {
         $terms[rawurldecode($term)] = rawurldecode(sprintf(__("%s [new]", "woocommerce-germanized"), $term));
     }
     wp_send_json($terms);
 }
 function sundaysea_update_cart2($cart_totals)
 {
     // Add Discount
     if (!empty($_POST['coupon_code'])) {
         WC()->cart->add_discount(sanitize_text_field($_POST['coupon_code']));
     } elseif (isset($_GET['remove_coupon'])) {
         WC()->cart->remove_coupon(wc_clean($_GET['remove_coupon']));
     }
     global $woocommerce;
     if (sizeof($woocommerce->cart->get_cart()) > 0) {
         foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
             // Skip product if no updated quantity was posted
             if (!isset($cart_totals[$cart_item_key]['qty'])) {
                 continue;
             }
             // Sanitize
             $quantity = apply_filters('woocommerce_stock_amount_cart_item', apply_filters('woocommerce_stock_amount', preg_replace("/[^0-9\\.]/", "", $cart_totals[$cart_item_key]['qty'])), $cart_item_key);
             if ("" === $quantity || $quantity == $values['quantity']) {
                 continue;
             }
             // Update cart validation
             $passed_validation = apply_filters('woocommerce_update_cart_validation', true, $cart_item_key, $values, $quantity);
             $_product = $values['data'];
             // is_sold_individually
             if ($_product->is_sold_individually() && $quantity > 1) {
                 $woocommerce->add_error(sprintf(__('You can only have 1 %s in your cart.', 'woocommerce'), $_product->get_title()));
                 $passed_validation = false;
             }
             if ($passed_validation) {
                 $woocommerce->cart->set_quantity($cart_item_key, $quantity, false);
             }
         }
         $woocommerce->cart->calculate_totals();
     }
 }
 /**
  * Check if we need to download a file and check validity.
  */
 public static function download_product()
 {
     $product_id = absint($_GET['download_file']);
     $product = wc_get_product($product_id);
     $data_store = WC_Data_Store::load('customer-download');
     if (!$product || !isset($_GET['key'], $_GET['order'])) {
         self::download_error(__('Invalid download link.', 'woocommerce'));
     }
     $download_ids = $data_store->get_downloads(array('user_email' => sanitize_email(str_replace(' ', '+', $_GET['email'])), 'order_key' => wc_clean($_GET['order']), 'product_id' => $product_id, 'download_id' => wc_clean(preg_replace('/\\s+/', ' ', $_GET['key'])), 'orderby' => 'downloads_remaining', 'order' => 'DESC', 'limit' => 1, 'return' => 'ids'));
     if (empty($download_ids)) {
         self::download_error(__('Invalid download link.', 'woocommerce'));
     }
     $download = new WC_Customer_Download(current($download_ids));
     self::check_order_is_valid($download);
     self::check_downloads_remaining($download);
     self::check_download_expiry($download);
     self::check_download_login_required($download);
     do_action('woocommerce_download_product', $download->get_user_email(), $download->get_order_key(), $download->get_product_id(), $download->get_user_id(), $download->get_download_id(), $download->get_order_id());
     $count = $download->get_download_count();
     $remaining = $download->get_downloads_remaining();
     $download->set_download_count($count++);
     $download->set_downloads_remaining($remaining--);
     $download->save();
     self::download($product->get_file_download_path($download->get_download_id()), $download->get_product_id());
 }
function product_search_sku($where)
{
    global $pagenow, $wpdb, $wp;
    //VAR_DUMP(http_build_query(array('post_type' => array('product','boobs'))));die();
    $type = array('product', 'jam');
    //var_dump(in_array('product', $wp->query_vars['post_type']));
    if (is_admin() && 'edit.php' != $pagenow || !is_search() || !isset($wp->query_vars['s']) || isset($wp->query_vars['post_type']) && 'product' != $wp->query_vars['post_type'] || isset($wp->query_vars['post_type']) && is_array($wp->query_vars['post_type']) && !in_array('product', $wp->query_vars['post_type'])) {
        return $where;
    }
    $search_ids = array();
    $terms = explode(',', $wp->query_vars['s']);
    foreach ($terms as $term) {
        //Include the search by id if admin area.
        if (is_admin() && is_numeric($term)) {
            $search_ids[] = $term;
        }
        // search for variations with a matching sku and return the parent.
        $sku_to_parent_id = $wpdb->get_col($wpdb->prepare("SELECT p.post_parent as post_id FROM {$wpdb->posts} as p join {$wpdb->postmeta} pm on p.ID = pm.post_id and pm.meta_key='_sku' and pm.meta_value LIKE '%%%s%%' where p.post_parent <> 0 group by p.post_parent", wc_clean($term)));
        //Search for a regular product that matches the sku.
        $sku_to_id = $wpdb->get_col($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_sku' AND meta_value LIKE '%%%s%%';", wc_clean($term)));
        $search_ids = array_merge($search_ids, $sku_to_id, $sku_to_parent_id);
    }
    $search_ids = array_filter(array_map('absint', $search_ids));
    if (sizeof($search_ids) > 0) {
        $where = str_replace(')))', ") OR ({$wpdb->posts}.ID IN (" . implode(',', $search_ids) . "))))", $where);
    }
    remove_filters_for_anonymous_class('posts_search', 'WC_Admin_Post_Types', 'product_search', 10);
    return $where;
}
 /**
  * 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 ('sep' !== $key) {
                 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();
                         $country = wc_clean($_POST[$key]);
                         $data[$key] = isset($countries[$country]) ? $countries[$country] : '';
                     } else {
                         $data[$key] = wc_clean($_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
         if ($mail = WC_germanized()->emails->get_email_instance_by_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;
 }
 /**
  * Edit a coupon.
  * @param int   $id
  * @param array $data
  */
 public static function edit_coupon($id, $data)
 {
     if (isset($data['billing_countries'])) {
         update_post_meta($id, 'billing_countries', wc_clean($data['billing_countries']));
     }
     if (isset($data['shipping_countries'])) {
         update_post_meta($id, 'shipping_countries', wc_clean($data['shipping_countries']));
     }
 }
 /**
  * Add shipping method to zone
  */
 public static function add_method($zone)
 {
     if (!empty($_GET['add_method']) && !empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'woocommerce_add_method')) {
         $type = wc_clean($_GET['method_type']);
         if ($type && ($method_id = $zone->add_shipping_method($type))) {
             echo '<div class="updated fade"><p>' . sprintf(__('Shipping method successfully created. <a href="%s">View method.</a>', SHIPPING_ZONES_TEXTDOMAIN), esc_url(add_query_arg('method', $method_id, add_query_arg('zone', $zone->zone_id, admin_url('admin.php?page=shipping_zones'))))) . '</p></div>';
         } else {
             echo '<div class="error"><p>' . __('Invalid shipping method', SHIPPING_ZONES_TEXTDOMAIN) . '</p></div>';
         }
     }
 }
Exemplo n.º 15
0
 /**
  * Save Dolibarr ID field on edit user pages
  *
  * @param mixed $user_id User ID of the user being saved
  *
  * @return void
  */
 public function save_customer_meta_fields($user_id)
 {
     $save_fields = $this->get_customer_meta_fields();
     foreach ($save_fields as $fieldset) {
         foreach ($fieldset['fields'] as $key => $field) {
             if (isset($_POST[$key])) {
                 update_user_meta($user_id, $key, wc_clean($_POST[$key]));
             }
         }
     }
 }
 /**
  * Process payment
  *
  * @param int $order_id
  */
 public function process_payment($order_id)
 {
     if (!$this->order_contains_subscription($order_id) && !wcs_is_subscription($order_id)) {
         return parent::process_payment($order_id);
     }
     $amazon_billing_agreement_id = isset($_POST['amazon_billing_agreement_id']) ? wc_clean($_POST['amazon_billing_agreement_id']) : '';
     try {
         if (!$amazon_billing_agreement_id) {
             throw new Exception(__('An Amazon payment method was not chosen.', 'woocommerce-gateway-amazon-payments-advanced'));
         }
         $order = new WC_Order($order_id);
         $order_total = $order->get_total();
         $this->log(__FUNCTION__, "Info: Beginning processing of payment for (subscription) order {$order_id} for the amount of {$order_total} {$order->get_order_currency()}.");
         // Set the Billing Agreement Details
         $this->set_billing_agreement_details($order, $amazon_billing_agreement_id);
         // Confirm the Billing Agreement
         $this->confirm_billing_agreement($order_id, $amazon_billing_agreement_id);
         // Get the Billing Agreement Details, with FULL address (now that we've confirmed)
         $result = $this->get_billing_agreement_details($order_id, $amazon_billing_agreement_id);
         // Store the subscription destination
         $this->store_subscription_destination($order_id, $result);
         // Store Billing Agreement ID on the order and it's subscriptions
         $result = update_post_meta($order_id, 'amazon_billing_agreement_id', $amazon_billing_agreement_id);
         if ($result) {
             $this->log(__FUNCTION__, "Info: Successfully stored billing agreement in meta for order {$order_id}.");
         } else {
             $this->log(__FUNCTION__, "Error: Failed to store billing agreement in meta for order {$order_id}.");
         }
         $subscriptions = wcs_get_subscriptions_for_order($order_id);
         foreach ($subscriptions as $subscription) {
             $result = update_post_meta($subscription->id, 'amazon_billing_agreement_id', $amazon_billing_agreement_id);
             if ($result) {
                 $this->log(__FUNCTION__, "Info: Successfully stored billing agreement in meta for subscription {$subscription->id} (parent order {$order_id}).");
             } else {
                 $this->log(__FUNCTION__, "Error: Failed to store billing agreement in meta for subscription {$subscription->id} (parent order {$order_id}).");
             }
         }
         // Authorize/Capture initial payment, if initial payment required
         if ($order_total > 0) {
             return $this->authorize_payment($order, $amazon_billing_agreement_id);
         }
         // No payment needed now, free trial or coupon used - mark order as complete
         $order->payment_complete();
         $this->log(__FUNCTION__, "Info: Zero-total initial payment for (subscription) order {$order_id}. Payment marked as complete.");
         // Remove items from cart
         WC()->cart->empty_cart();
         // Return thank you page redirect
         return array('result' => 'success', 'redirect' => $this->get_return_url($order));
     } catch (Exception $e) {
         $this->log(__FUNCTION__, "Error: Exception encountered: {$e->getMessage()}");
         wc_add_notice(sprintf(__('Error: %s', 'woocommerce-gateway-amazon-payments-advanced'), $e->getMessage()), 'error');
         return;
     }
 }
 public static function json_search_customer_name($query)
 {
     global $wpdb;
     $term = wc_clean(stripslashes($_GET['term']));
     if (method_exists($wpdb, 'esc_like')) {
         $term = $wpdb->esc_like($term);
     } else {
         $term = like_escape($term);
     }
     $query->query_from .= " INNER JOIN {$wpdb->usermeta} AS user_name ON {$wpdb->users}.ID = user_name.user_id AND ( user_name.meta_key = 'first_name' OR user_name.meta_key = 'last_name' ) ";
     $query->query_where .= $wpdb->prepare(" OR user_name.meta_value LIKE %s ", '%' . $term . '%');
 }
function tapfiliate()
{
    global $post;
    $postName = $post ? $post->post_name : null;
    $tap_account_id = get_option('tap_account_id');
    $integrate_for = get_option('integrate_for');
    $thank_you_page = get_option('thank_you_page');
    $query_parameter_transaction_id = get_option('query_parameter_transaction_id');
    $query_parameter_transaction_amount = get_option('query_parameter_transaction_amount');
    ?>
<script src="//tapfiliate.com/tapfiliate.js" type="text/javascript" async></script>
<script type="text/javascript">
  window['TapfiliateObject'] = i = 'tap';
  window[i] = window[i] || function () {
      (window[i].q = window[i].q || []).push(arguments);
  };

  tap('create', '<?php 
    echo $tap_account_id;
    ?>
');
  <?php 
    if ($integrate_for == 'wp') {
        if ($postName == $thank_you_page) {
            $cid = isset($_GET[$query_parameter_transaction_id]) && !empty($_GET[$query_parameter_transaction_id]) ? "'{$_GET[$query_parameter_transaction_id]}'" : 'null';
            $cam = isset($_GET[$query_parameter_transaction_amount]) && !empty($_GET[$query_parameter_transaction_amount]) ? $_GET[$query_parameter_transaction_amount] : 'null';
            echo "tap('conversion', {$cid}, {$cam});";
        } else {
            echo "tap('detectClick');";
        }
    } elseif ($integrate_for == 'wc') {
        if (function_exists("is_order_received_page") && is_order_received_page()) {
            if (isset($GLOBALS['order-received'])) {
                $order_id = apply_filters('woocommerce_thankyou_order_id', absint($GLOBALS['order-received']));
                $order_key = apply_filters('woocommerce_thankyou_order_key', empty($_GET['key']) ? '' : wc_clean($_GET['key']));
                if ($order_id > 0) {
                    $order = new WC_Order($order_id);
                    if ($order->order_key != $order_key) {
                        unset($order);
                    }
                }
                echo "tap('conversion', '{$order->id}', {$order->get_total()});";
            }
        } else {
            echo "tap('detectClick');";
        }
    }
    ?>
</script>
<?php 
}
 /**
  * Check if we need to download a file and check validity.
  */
 public static function download_product()
 {
     $product_id = absint($_GET['download_file']);
     $_product = wc_get_product($product_id);
     $download_data = self::get_download_data(array('product_id' => $product_id, 'order_key' => wc_clean($_GET['order']), 'email' => sanitize_email(str_replace(' ', '+', $_GET['email'])), 'download_id' => wc_clean(isset($_GET['key']) ? preg_replace('/\\s+/', ' ', $_GET['key']) : '')));
     if ($_product && $download_data) {
         self::check_current_user_can_download($download_data);
         do_action('woocommerce_download_product', $download_data->user_email, $download_data->order_key, $download_data->product_id, $download_data->user_id, $download_data->download_id, $download_data->order_id);
         self::count_download($download_data);
         self::download($_product->get_file_download_path($download_data->download_id), $download_data->product_id);
     } else {
         self::download_error(__('Invalid download link.', 'woocommerce'));
     }
 }
 /**
  * Get and sanitize posted attribute data
  * @return array
  */
 private static function get_posted_attribute()
 {
     $attribute = array('attribute_label' => isset($_POST['attribute_label']) ? wc_clean(stripslashes($_POST['attribute_label'])) : '', 'attribute_name' => isset($_POST['attribute_name']) ? wc_sanitize_taxonomy_name(stripslashes($_POST['attribute_name'])) : '', 'attribute_type' => isset($_POST['attribute_type']) ? wc_clean($_POST['attribute_type']) : 'select', 'attribute_orderby' => isset($_POST['attribute_orderby']) ? wc_clean($_POST['attribute_orderby']) : '', 'attribute_public' => isset($_POST['attribute_public']) ? 1 : 0);
     if (empty($attribute['attribute_type'])) {
         $attribute['attribute_type'] = 'select';
     }
     if (empty($attribute['attribute_label'])) {
         $attribute['attribute_label'] = ucfirst($attribute['attribute_name']);
     }
     if (empty($attribute['attribute_name'])) {
         $attribute['attribute_name'] = wc_sanitize_taxonomy_name($attribute['attribute_label']);
     }
     return $attribute;
 }
 /**
  * Check Response for PDT.
  */
 public function check_response()
 {
     if (empty($_REQUEST['cm']) || empty($_REQUEST['tx']) || empty($_REQUEST['st'])) {
         return;
     }
     $order_id = wc_clean(stripslashes($_REQUEST['cm']));
     $status = wc_clean(strtolower(stripslashes($_REQUEST['st'])));
     $amount = wc_clean(stripslashes($_REQUEST['amt']));
     $transaction = wc_clean(stripslashes($_REQUEST['tx']));
     if (!($order = $this->get_paypal_order($order_id)) || !$order->has_status('pending')) {
         return false;
     }
     $transaction_result = $this->validate_transaction($transaction);
     WC_Gateway_Paypal::log('PDT Transaction Result: ' . print_r($transaction_result, true));
     update_post_meta($order->get_id(), '_paypal_status', $status);
     update_post_meta($order->get_id(), '_transaction_id', $transaction);
     if ($transaction_result) {
         if ('completed' === $status) {
             if ($order->get_total() != $amount) {
                 WC_Gateway_Paypal::log('Payment error: Amounts do not match (amt ' . $amount . ')');
                 $this->payment_on_hold($order, sprintf(__('Validation error: PayPal amounts do not match (amt %s).', 'woocommerce'), $amount));
             } else {
                 $this->payment_complete($order, $transaction, __('PDT payment completed', 'woocommerce'));
                 // Log paypal transaction fee and other meta data.
                 if (!empty($transaction_result['mc_fee'])) {
                     update_post_meta($order->get_id(), 'PayPal Transaction Fee', $transaction_result['mc_fee']);
                 }
                 if (!empty($transaction_result['payer_email'])) {
                     update_post_meta($order->get_id(), 'Payer PayPal address', $transaction_result['payer_email']);
                 }
                 if (!empty($transaction_result['first_name'])) {
                     update_post_meta($order->get_id(), 'Payer first name', $transaction_result['first_name']);
                 }
                 if (!empty($transaction_result['last_name'])) {
                     update_post_meta($order->get_id(), 'Payer last name', $transaction_result['last_name']);
                 }
                 if (!empty($transaction_result['payment_type'])) {
                     update_post_meta($order->get_id(), 'Payment type', $transaction_result['payment_type']);
                 }
             }
         } else {
             if ('authorization' === $transaction_result['pending_reason']) {
                 $this->payment_on_hold($order, __('Payment authorized. Change payment status to processing or complete to capture funds.', 'woocommerce'));
             } else {
                 $this->payment_on_hold($order, sprintf(__('Payment pending (%s).', 'woocommerce'), $transaction_result['pending_reason']));
             }
         }
     }
 }
 /**
  * Output widget.
  *
  * @see WP_Widget
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     global $_chosen_attributes;
     if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
         return;
     }
     // Price
     $min_price = isset($_GET['min_price']) ? wc_clean($_GET['min_price']) : 0;
     $max_price = isset($_GET['max_price']) ? wc_clean($_GET['max_price']) : 0;
     // Rating
     $min_rating = isset($_GET['min_rating']) ? wc_clean($_GET['min_rating']) : 0;
     if (0 < count($_chosen_attributes) || 0 < $min_price || 0 < $max_price || 0 < $min_rating) {
         $this->widget_start($args, $instance);
         echo '<ul>';
         // Attributes
         if (!is_null($_chosen_attributes)) {
             foreach ($_chosen_attributes as $taxonomy => $data) {
                 foreach ($data['terms'] as $term_slug) {
                     if (!($term = get_term_by('slug', $term_slug, $taxonomy))) {
                         continue;
                     }
                     $filter_name = 'filter_' . sanitize_title(str_replace('pa_', '', $taxonomy));
                     $current_filter = isset($_GET[$filter_name]) ? explode(',', wc_clean($_GET[$filter_name])) : array();
                     $current_filter = array_map('sanitize_title', $current_filter);
                     $new_filter = array_diff($current_filter, array($term_slug));
                     $link = remove_query_arg(array('add-to-cart', $filter_name));
                     if (sizeof($new_filter) > 0) {
                         $link = add_query_arg($filter_name, implode(',', $new_filter), $link);
                     }
                     echo '<li class="chosen"><a title="' . esc_attr__('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . esc_html($term->name) . '</a></li>';
                 }
             }
         }
         if ($min_price) {
             $link = remove_query_arg('min_price');
             echo '<li class="chosen"><a title="' . esc_attr__('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . __('Min', 'woocommerce') . ' ' . wc_price($min_price) . '</a></li>';
         }
         if ($max_price) {
             $link = remove_query_arg('max_price');
             echo '<li class="chosen"><a title="' . esc_attr__('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . __('Max', 'woocommerce') . ' ' . wc_price($max_price) . '</a></li>';
         }
         if ($min_rating) {
             $link = remove_query_arg('min_rating');
             echo '<li class="chosen"><a title="' . esc_attr__('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . sprintf(__('Rated %s and above', 'woocommerce'), $min_rating) . '</a></li>';
         }
         echo '</ul>';
         $this->widget_end($args);
     }
 }
 /**
  * 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');
     }
 }
 /**
  * Widget function
  *
  * @see WP_Widget
  * @access public
  * @param array $args
  * @param array $instance
  * @return void
  */
 public function widget($args, $instance)
 {
     global $wp_query;
     extract($args);
     $title = !empty($instance['title']) ? $before_title . $instance['title'] . $after_title : '';
     $output = '';
     if (1 != $wp_query->found_posts || woocommerce_products_will_display()) {
         $output .= '<ul id="nm-product-sorting" class="nm-product-sorting">';
         $orderby = isset($_GET['orderby']) ? wc_clean($_GET['orderby']) : apply_filters('woocommerce_default_catalog_orderby', get_option('woocommerce_default_catalog_orderby'));
         $orderby == ($orderby === 'title') ? 'menu_order' : $orderby;
         // Fixed: 'title' is default before WooCommerce settings are saved
         $catalog_orderby_options = apply_filters('woocommerce_catalog_orderby', array('menu_order' => __('Default', 'nm-framework'), 'popularity' => __('Popularity', 'nm-framework'), 'rating' => __('Average rating', 'nm-framework'), 'date' => __('Newness', 'nm-framework'), 'price' => __('Price: Low to High', 'nm-framework'), 'price-desc' => __('Price: High to Low', 'nm-framework')));
         if (get_option('woocommerce_enable_review_rating') === 'no') {
             unset($catalog_orderby_options['rating']);
         }
         /* Build entire current page URL (including query strings) */
         global $wp;
         $link = home_url($wp->request);
         // Base page URL
         // Unset query strings used for Ajax shop filters
         unset($_GET['shop_load']);
         unset($_GET['_']);
         $qs_count = count($_GET);
         // Any query strings to add?
         if ($qs_count > 0) {
             $i = 0;
             $link .= '?';
             // Build query string
             foreach ($_GET as $key => $value) {
                 $i++;
                 $link .= $key . '=' . $value;
                 if ($i != $qs_count) {
                     $link .= '&';
                 }
             }
         }
         foreach ($catalog_orderby_options as $id => $name) {
             if ($orderby == $id) {
                 $output .= '<li class="active">' . esc_attr($name) . '</li>';
             } else {
                 // Add 'orderby' URL query string
                 $link = add_query_arg('orderby', $id, $link);
                 $output .= '<li><a href="' . esc_url($link) . '">' . esc_attr($name) . '</a></li>';
             }
         }
         $output .= '</ul>';
     }
     echo $before_widget . $title . $output . $after_widget;
 }
Exemplo n.º 25
0
 /**
  * validate_services_field function.
  *
  * @access public
  * @param mixed $key
  * @return void
  */
 public function validate_services_field($key)
 {
     $services = array();
     $posted_services = $_POST['shipping_id_service'];
     foreach ($posted_services as $code => $settings) {
         $services[$code] = array('order' => wc_clean($settings['order']), 'enabled' => isset($settings['enabled']) ? true : false);
         foreach ($this->services[$code]['services'] as $key => $name) {
             $services[$code][$key]['enabled'] = isset($settings[$key]['enabled']) ? true : false;
             $services[$code][$key]['adjustment'] = wc_clean($settings[$key]['adjustment']);
             $services[$code][$key]['adjustment_percent'] = wc_clean($settings[$key]['adjustment_percent']);
         }
     }
     // die();
     return $services;
 }
Exemplo n.º 26
0
 public function install_standard_rates()
 {
     //  delete previous inserted standard rates
     $tax_rates = $this->get_tax_rates();
     foreach ($tax_rates as $tax_rate) {
         $tax_rate_name = sprintf("EU VAT (%s)", $tax_rate->tax_rate_country);
         if (0 == strpos($tax_rate->tax_rate_name, $tax_rate_name)) {
             WC_Tax::_delete_tax_rate($tax_rate->tax_rate_id);
         }
     }
     foreach ($this->tax_rates_data as $key => $value) {
         $tax_rate = array('tax_rate_country' => $key, 'tax_rate_state' => '*', 'tax_rate' => $value["standard_rate"], 'tax_rate_name' => sprintf("EU VAT (%s) %s%%", $key, $value["standard_rate"]), 'tax_rate_priority' => 1, 'tax_rate_compound' => 1, 'tax_rate_shipping' => 1, 'tax_rate_class' => '');
         $tax_rate_id = WC_Tax::_insert_tax_rate($tax_rate);
         WC_Tax::_update_tax_rate_postcodes($tax_rate_id, wc_clean('*'));
         WC_Tax::_update_tax_rate_cities($tax_rate_id, wc_clean('*'));
     }
 }
Exemplo n.º 27
0
 /**
  * When using geolocation via ajax, to bust cache, redirect if the location hash does not equal the querystring.
  *
  * This prevents caching of the wrong data for this request.
  */
 public static function geolocation_ajax_redirect()
 {
     if ('geolocation_ajax' === get_option('woocommerce_default_customer_address') && !is_checkout() && !is_ajax()) {
         $location_hash = self::geolocation_ajax_get_location_hash();
         $current_hash = isset($_GET['v']) ? wc_clean($_GET['v']) : '';
         if (empty($current_hash) || $current_hash !== $location_hash) {
             global $wp;
             $redirect_url = trailingslashit(home_url($wp->request));
             if (!get_option('permalink_structure')) {
                 $redirect_url = add_query_arg($wp->query_string, '', $redirect_url);
             }
             $redirect_url = add_query_arg('v', $location_hash, remove_query_arg('v', $redirect_url));
             wp_safe_redirect(esc_url_raw($redirect_url), 307);
             exit;
         }
     }
 }
Exemplo n.º 28
0
/**
 * Output the product sorting options.
 *
 * @subpackage	Loop
 */
function heni_catalog_ordering()
{
    global $wp_query;
    if (1 == $wp_query->found_posts || !woocommerce_products_will_display()) {
        return;
    }
    $orderby = isset($_GET['orderby']) ? wc_clean($_GET['orderby']) : apply_filters('woocommerce_default_catalog_orderby', get_option('woocommerce_default_catalog_orderby'));
    $show_default_orderby = 'menu_order' === apply_filters('woocommerce_default_catalog_orderby', get_option('woocommerce_default_catalog_orderby'));
    $catalog_orderby_options = apply_filters('woocommerce_catalog_orderby', array('menu_order' => __('Default sorting', 'woocommerce')));
    if (!$show_default_orderby) {
        unset($catalog_orderby_options['menu_order']);
    }
    if (get_option('woocommerce_enable_review_rating') === 'no') {
        unset($catalog_orderby_options['rating']);
    }
    wc_get_template('loop/orderby.php', array('catalog_orderby_options' => $catalog_orderby_options, 'orderby' => $orderby, 'show_default_orderby' => $show_default_orderby));
}
 /**
  * Get current page URL for layered nav items.
  * @return string
  */
 protected function get_page_base_url()
 {
     if (defined('SHOP_IS_ON_FRONT')) {
         $link = home_url();
     } elseif (is_post_type_archive('product') || is_page(wc_get_page_id('shop'))) {
         $link = get_post_type_archive_link('product');
     } else {
         $link = get_term_link(get_query_var('term'), get_query_var('taxonomy'));
     }
     // Min/Max
     if (isset($_GET['min_price'])) {
         $link = add_query_arg('min_price', wc_clean($_GET['min_price']), $link);
     }
     if (isset($_GET['max_price'])) {
         $link = add_query_arg('max_price', wc_clean($_GET['max_price']), $link);
     }
     // Orderby
     if (isset($_GET['orderby'])) {
         $link = add_query_arg('orderby', wc_clean($_GET['orderby']), $link);
     }
     /**
      * Search Arg.
      * To support quote characters, first they are decoded from &quot; entities, then URL encoded.
      */
     if (get_search_query()) {
         $link = add_query_arg('s', rawurlencode(htmlspecialchars_decode(get_search_query())), $link);
     }
     // Post Type Arg
     if (isset($_GET['post_type'])) {
         $link = add_query_arg('post_type', wc_clean($_GET['post_type']), $link);
     }
     // All current filters
     if ($_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes()) {
         foreach ($_chosen_attributes as $name => $data) {
             $filter_name = sanitize_title(str_replace('pa_', '', $name));
             if (!empty($data['terms'])) {
                 $link = add_query_arg('filter_' . $filter_name, implode(',', $data['terms']), $link);
             }
             if ('or' == $data['query_type']) {
                 $link = add_query_arg('query_type_' . $filter_name, 'or', $link);
             }
         }
     }
     return $link;
 }
 /**
  * Get current page URL for layered nav items.
  * @return string
  */
 protected function get_page_base_url()
 {
     if (defined('SHOP_IS_ON_FRONT')) {
         $link = home_url();
     } elseif (is_post_type_archive('product') || is_page(wc_get_page_id('shop'))) {
         $link = get_post_type_archive_link('product');
     } else {
         $link = get_term_link(get_query_var('term'), get_query_var('taxonomy'));
     }
     // Min/Max
     if (isset($_GET['min_price'])) {
         $link = add_query_arg('min_price', wc_clean($_GET['min_price']), $link);
     }
     if (isset($_GET['max_price'])) {
         $link = add_query_arg('max_price', wc_clean($_GET['max_price']), $link);
     }
     // Orderby
     if (isset($_GET['orderby'])) {
         $link = add_query_arg('orderby', wc_clean($_GET['orderby']), $link);
     }
     // Search Arg
     if (get_search_query()) {
         $link = add_query_arg('s', get_search_query(), $link);
     }
     // Post Type Arg
     if (isset($_GET['post_type'])) {
         $link = add_query_arg('post_type', wc_clean($_GET['post_type']), $link);
     }
     return $link;
 }