function fflcommerce_edit_address() { $account_url = get_permalink(fflcommerce_get_page_id(FFLCOMMERCE_MY_ACCOUNT)); $user_id = get_current_user_id(); $load_address = fflcommerce_get_address_to_edit(); $address = fflcommerce_get_address_fields($load_address, $user_id); if (isset($_POST['save_address']) && fflcommerce::verify_nonce(FFLCOMMERCE_EDIT_ADDRESS)) { if ($user_id > 0) { foreach ($address as &$field) { if (isset($_POST[$field['name']])) { $field['value'] = fflcommerce_clean($_POST[$field['name']]); update_user_meta($user_id, $field['name'], $field['value']); } } do_action('fflcommerce_user_edit_address', $user_id, $address); } } fflcommerce_render('shortcode/my_account/edit_address', array('url' => add_query_arg('address', $load_address, apply_filters('fflcommerce_get_edit_address_page_id', get_permalink(fflcommerce_get_page_id(FFLCOMMERCE_EDIT_ADDRESS)))), 'account_url' => $account_url, 'load_address' => $load_address, 'address' => $address)); }
/** * Format decimal numbers according to current settings. * * @param float|string $number Expects either a float or a string with a decimal separator only (no thousands) * @param mixed $dp number of decimal points to use, blank to use configured decimals or false to avoid all rounding. * @param boolean $trim_zeros from end of string * @return string */ function fflcommerce_format_decimal($number, $dp = false, $trim_zeros = false) { $locale = localeconv(); $options = FFLCommerce_Base::get_options(); $decimals = array($options->get('fflcommerce_price_decimal_sep'), $locale['decimal_point'], $locale['mon_decimal_point']); // Remove locale from string if (!is_float($number)) { $number = fflcommerce_clean(str_replace($decimals, '.', $number)); } if ($dp !== false) { $dp = intval($dp == "" ? $options->get('fflcommerce_price_num_decimals') : $dp); $number = number_format(floatval($number), $dp, '.', ''); // DP is false - don't use number format, just return a string in our format } elseif (is_float($number)) { $number = fflcommerce_clean(str_replace($decimals, '.', strval($number))); } if ($trim_zeros && strstr($number, '.')) { $number = rtrim(rtrim($number, '0'), '.'); } return $number; }
function fflcommerce_pay_action() { if (!is_fflcommerce_single_page(FFLCOMMERCE_PAY)) { return; } if (isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id'])) { // Pay for existing order $order_key = urldecode($_GET['order']); $order_id = (int) $_GET['order_id']; $order = new fflcommerce_order($order_id); if ($order->id == $order_id && $order->order_key == $order_key && $order->status == 'pending') { // Set customer location to order location if ($order->billing_country) { fflcommerce_customer::set_country($order->billing_country); } if ($order->billing_state) { fflcommerce_customer::set_state($order->billing_state); } if ($order->billing_postcode) { fflcommerce_customer::set_postcode($order->billing_postcode); } // Pay form was posted - process payment if (isset($_POST['pay']) && fflcommerce::verify_nonce('pay')) { // Update payment method if ($order->order_total > 0) { $payment_method = fflcommerce_clean($_POST['payment_method']); $data = (array) maybe_unserialize(get_post_meta($order_id, 'order_data', true)); $data['payment_method'] = $payment_method; update_post_meta($order_id, 'order_data', $data); $available_gateways = fflcommerce_payment_gateways::get_available_payment_gateways(); $result = $available_gateways[$payment_method]->process_payment($order_id); // Redirect to success/confirmation/payment page if ($result['result'] == 'success') { wp_safe_redirect($result['redirect']); exit; } } else { // No payment was required for order $order->payment_complete(); // filter redirect page $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks')); wp_safe_redirect(get_permalink($checkout_redirect)); exit; } } } elseif ($order->status != 'pending') { fflcommerce::add_error(__('Your order has already been paid for. Please contact us if you need assistance.', 'fflcommerce')); } else { fflcommerce::add_error(__('Invalid order.', 'fflcommerce')); } } else { // Pay for order after checkout step if (isset($_GET['order'])) { $order_id = $_GET['order']; } else { $order_id = 0; } if (isset($_GET['key'])) { $order_key = $_GET['key']; } else { $order_key = ''; } if ($order_id > 0) { $order = new fflcommerce_order($order_id); if ($order->order_key != $order_key || $order->status != 'pending') { wp_safe_redirect(apply_filters('fflcommerce_get_myaccount_page_id', get_permalink(fflcommerce_get_page_id('myaccount')))); exit; } } else { wp_safe_redirect(apply_filters('fflcommerce_get_myaccount_page_id', get_permalink(fflcommerce_get_page_id('myaccount')))); exit; } } }
/** * Validate the checkout */ public function validate_checkout() { if (fflcommerce_cart::is_empty()) { fflcommerce::add_error(sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage →</a>', 'fflcommerce'), home_url())); } // Process Discount Codes if (!empty($_POST['coupon_code'])) { $coupon = sanitize_title($_POST['coupon_code']); fflcommerce_cart::add_discount($coupon); } foreach (fflcommerce_cart::get_coupons() as $coupon) { fflcommerce_cart::is_valid_coupon($coupon); } // Checkout fields $this->posted['shipping_method'] = ''; $this->posted['shipping_service'] = ''; if (isset($_POST['shipping_method'])) { $shipping_method = fflcommerce_clean($_POST['shipping_method']); $shipping_data = explode(':', $shipping_method); $this->posted['shipping_method'] = $shipping_data[0]; $this->posted['shipping_service'] = $shipping_data[1]; } $this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? fflcommerce_clean($_POST['shiptobilling']) : ''; $this->posted['payment_method'] = isset($_POST['payment_method']) ? fflcommerce_clean($_POST['payment_method']) : ''; $this->posted['order_comments'] = isset($_POST['order_comments']) ? fflcommerce_clean($_POST['order_comments']) : ''; $this->posted['terms'] = isset($_POST['terms']) ? fflcommerce_clean($_POST['terms']) : ''; $this->posted['create_account'] = isset($_POST['create_account']) ? fflcommerce_clean($_POST['create_account']) : ''; $this->posted['account_username'] = isset($_POST['account_username']) ? fflcommerce_clean($_POST['account_username']) : ''; $this->posted['account_password'] = isset($_POST['account_password']) ? fflcommerce_clean($_POST['account_password']) : ''; $this->posted['account_password_2'] = isset($_POST['account_password_2']) ? fflcommerce_clean($_POST['account_password_2']) : ''; if (fflcommerce_cart::get_total(false) == 0) { $this->posted['payment_method'] = 'no_payment'; } // establish customer billing and shipping locations if (fflcommerce_cart::ship_to_billing_address_only()) { $this->posted['shiptobilling'] = 'true'; } $country = isset($_POST['billing_country']) ? fflcommerce_clean($_POST['billing_country']) : ''; $state = isset($_POST['billing_state']) ? fflcommerce_clean($_POST['billing_state']) : ''; $allowed_countries = FFLCommerce_Base::get_options()->get('fflcommerce_allowed_countries'); if ($allowed_countries === 'specific') { $specific_countries = FFLCommerce_Base::get_options()->get('fflcommerce_specific_allowed_countries'); if (!in_array($country, $specific_countries)) { fflcommerce::add_error(__('Invalid billing country.', 'fflcommerce')); return; } } if (fflcommerce_countries::country_has_states($country)) { $states = fflcommerce_countries::get_states($country); if (!in_array($state, array_keys($states))) { fflcommerce::add_error(__('Invalid billing state.', 'fflcommerce')); return; } } $postcode = isset($_POST['billing_postcode']) ? fflcommerce_clean($_POST['billing_postcode']) : ''; $ship_to_billing = FFLCommerce_Base::get_options()->get('fflcommerce_ship_to_billing_address_only') == 'yes'; fflcommerce_customer::set_location($country, $state, $postcode); if (FFLCommerce_Base::get_options()->get('fflcommerce_calc_shipping') == 'yes') { if ($ship_to_billing || !empty($_POST['shiptobilling'])) { fflcommerce_customer::set_shipping_location($country, $state, $postcode); } else { $country = isset($_POST['shipping_country']) ? fflcommerce_clean($_POST['shipping_country']) : ''; $state = isset($_POST['shipping_state']) ? fflcommerce_clean($_POST['shipping_state']) : ''; $postcode = isset($_POST['shipping_postcode']) ? fflcommerce_clean($_POST['shipping_postcode']) : ''; if ($allowed_countries === 'specific') { $specific_countries = FFLCommerce_Base::get_options()->get('fflcommerce_specific_allowed_countries'); if (!in_array($country, $specific_countries)) { fflcommerce::add_error(__('Invalid shipping country.', 'fflcommerce')); return; } } if (fflcommerce_countries::country_has_states($country)) { $states = fflcommerce_countries::get_states($country); if (!in_array($state, array_keys($states))) { fflcommerce::add_error(__('Invalid shipping state.', 'fflcommerce')); return; } } fflcommerce_customer::set_shipping_location($country, $state, $postcode); } } // Billing Information foreach ($this->billing_fields as $field) { $field = apply_filters('fflcommerce_billing_field', $field); $this->posted[$field['name']] = isset($_POST[$field['name']]) ? fflcommerce_clean($_POST[$field['name']]) : ''; // Format if (isset($field['format'])) { switch ($field['format']) { case 'postcode': $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break; } } // Required if ($field['name'] == 'billing_state' && fflcommerce_customer::has_valid_shipping_state()) { $field['required'] = false; } if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) { fflcommerce::add_error($field['label'] . __(' (billing) is a required field.', 'fflcommerce')); } if ($field['name'] == 'billing_euvatno') { $vatno = isset($this->posted['billing_euvatno']) ? $this->posted['billing_euvatno'] : ''; $vatno = str_replace(' ', '', $vatno); $country = fflcommerce_tax::get_customer_country(); // strip any country code from the beginning of the number if (strpos($vatno, $country) === 0) { $vatno = substr($vatno, strlen($country)); } if ($vatno != '') { $url = 'http://isvat.appspot.com/' . $country . '/' . $vatno . '/'; $httpRequest = curl_init(); curl_setopt($httpRequest, CURLOPT_FAILONERROR, true); curl_setopt($httpRequest, CURLOPT_RETURNTRANSFER, true); curl_setopt($httpRequest, CURLOPT_HEADER, false); curl_setopt($httpRequest, CURLOPT_URL, $url); $result = curl_exec($httpRequest); curl_close($httpRequest); if ($result === 'false') { fflcommerce_log('EU VAT validation error with URL: ' . $url); fflcommerce::add_error($field['label'] . __(' (billing) is not a valid VAT Number. Leave it blank to disable VAT validation. (VAT may be charged depending on your location)', 'fflcommerce')); } else { $this->valid_euvatno = fflcommerce_countries::get_base_country() != fflcommerce_tax::get_customer_country() && fflcommerce_countries::is_eu_country(fflcommerce_tax::get_customer_country()); } } } // Validation if (isset($field['validate']) && !empty($this->posted[$field['name']])) { switch ($field['validate']) { case 'phone': if (!fflcommerce_validation::is_phone($this->posted[$field['name']])) { fflcommerce::add_error($field['label'] . __(' (billing) is not a valid number.', 'fflcommerce')); } break; case 'email': if (!fflcommerce_validation::is_email($this->posted[$field['name']])) { fflcommerce::add_error($field['label'] . __(' (billing) is not a valid email address.', 'fflcommerce')); } break; case 'postcode': if (!fflcommerce_validation::is_postcode($this->posted[$field['name']], $_POST['billing_country'])) { fflcommerce::add_error($field['label'] . __(' (billing) is not a valid postcode/ZIP.', 'fflcommerce')); } else { $this->posted[$field['name']] = fflcommerce_validation::format_postcode($this->posted[$field['name']], $_POST['billing_country']); } break; } } } // Shipping Information if (fflcommerce_shipping::is_enabled() && !fflcommerce_cart::ship_to_billing_address_only() && empty($this->posted['shiptobilling'])) { foreach ($this->shipping_fields as $field) { $field = apply_filters('fflcommerce_shipping_field', $field); if (isset($_POST[$field['name']])) { $this->posted[$field['name']] = fflcommerce_clean($_POST[$field['name']]); } else { $this->posted[$field['name']] = ''; } // Format if (isset($field['format'])) { switch ($field['format']) { case 'postcode': $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break; } } // Required if ($field['name'] == 'shipping_state' && fflcommerce_customer::has_valid_shipping_state()) { $field['required'] = false; } if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) { fflcommerce::add_error($field['label'] . __(' (shipping) is a required field.', 'fflcommerce')); } // Validation if (isset($field['validate']) && !empty($this->posted[$field['name']])) { switch ($field['validate']) { case 'postcode': if (!fflcommerce_validation::is_postcode($this->posted[$field['name']], $country)) { fflcommerce::add_error($field['label'] . __(' (shipping) is not a valid postcode/ZIP.', 'fflcommerce')); } else { $this->posted[$field['name']] = fflcommerce_validation::format_postcode($this->posted[$field['name']], $country); } break; } } } } if ($this->must_register && empty($this->posted['create_account'])) { fflcommerce::add_error(__('Sorry, you must agree to creating an account', 'fflcommerce')); } if ($this->must_register || empty($user_id) && $this->posted['create_account']) { if (!$this->show_signup) { fflcommerce::add_error(__('Sorry, the shop owner has disabled guest purchases.', 'fflcommerce')); } if (empty($this->posted['account_username'])) { fflcommerce::add_error(__('Please enter an account username.', 'fflcommerce')); } if (empty($this->posted['account_password'])) { fflcommerce::add_error(__('Please enter an account password.', 'fflcommerce')); } if ($this->posted['account_password_2'] !== $this->posted['account_password']) { fflcommerce::add_error(__('Passwords do not match.', 'fflcommerce')); } // Check the username if (!validate_username($this->posted['account_username'])) { fflcommerce::add_error(__('Invalid email/username.', 'fflcommerce')); } elseif (username_exists($this->posted['account_username'])) { fflcommerce::add_error(__('An account is already registered with that username. Please choose another.', 'fflcommerce')); } // Check the e-mail address if (email_exists($this->posted['billing_email'])) { fflcommerce::add_error(__('An account is already registered with your email address. Please login.', 'fflcommerce')); } } // Terms if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && fflcommerce_get_page_id('terms') > 0) { fflcommerce::add_error(__('You must accept our Terms & Conditions.', 'fflcommerce')); } if (fflcommerce_cart::needs_shipping()) { // Shipping Method $available_methods = fflcommerce_shipping::get_available_shipping_methods(); if (!isset($available_methods[$this->posted['shipping_method']])) { fflcommerce::add_error(__('Invalid shipping method.', 'fflcommerce')); } } }
function fflcommerce_process_shop_order_meta($post_id) { $fflcommerce_options = FFLCommerce_Base::get_options(); $fflcommerce_errors = array(); $order = new fflcommerce_order($post_id); // Get old data + attributes $data = (array) maybe_unserialize(get_post_meta($post_id, 'order_data', true)); //Get old order items $old_order_items = (array) maybe_unserialize(get_post_meta($post_id, 'order_items', true)); // Add/Replace data to array $customerDetails = array('billing_first_name', 'billing_last_name', 'billing_company', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_postcode', 'billing_country', 'billing_state', 'billing_email', 'billing_phone', 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_postcode', 'shipping_country', 'shipping_state'); $order_fields = array('shipping_method', 'shipping_service', 'payment_method', 'order_subtotal', 'order_discount_subtotal', 'order_shipping', 'order_discount', 'order_discount_coupons', 'order_tax_total', 'order_shipping_tax', 'order_total', 'order_total_prices_per_tax_class_ex_tax'); /* Pre-fill the customer addresses */ foreach ($customerDetails as $key) { $order_fields[] = $key; /* Checks if this is a new order from "Add Order" button */ if (!empty($_POST['auto_draft']) && !empty($_POST['customer_user']) && empty($_POST[$key])) { $data[$key] = get_user_meta($_POST['customer_user'], $key, true); } } //run stripslashes on all valid fields foreach ($order_fields as $field_name) { if (isset($_POST[$field_name])) { $data[$field_name] = stripslashes($_POST[$field_name]); } } // Sanitize numeric values $data['order_total'] = fflcommerce_sanitize_num($data['order_total']); $data['order_subtotal'] = fflcommerce_sanitize_num($data['order_subtotal']); // if a shipping or payment methods has changed, update the method title for pretty display if (isset($_POST['shipping_method'])) { $data['shipping_service'] = ''; $shipping_methods = fflcommerce_shipping::get_all_methods(); if (!empty($shipping_methods)) { foreach ($shipping_methods as $method) { if ($_POST['shipping_method'] == $method->id) { $data['shipping_service'] = $method->title; } } } } if (isset($_POST['payment_method'])) { $data['payment_method_title'] = ''; $payment_methods = fflcommerce_payment_gateways::get_available_payment_gateways(); if (!empty($payment_methods)) { foreach ($payment_methods as $method) { if ($_POST['payment_method'] == $method->id) { $data['payment_method_title'] = $method->title; } } } } // if total tax has been modified from order tax, then create a customized tax array // just for the order. At this point, we no longer know about multiple tax classes. // Even if we used the old tax array data, we still don't know how to break down // the amounts since they're customized. if (isset($data['order_tax_total']) && $order->get_total_tax() != $data['order_tax_total']) { $new_tax = $data['order_tax_total']; $data['order_tax'] = fflcommerce_tax::create_custom_tax($data['order_total'] - $data['order_tax_total'], $data['order_tax_total'], $data['order_shipping_tax'], isset($data['order_tax_divisor']) ? $data['order_tax_divisor'] : null); } // Customer update_post_meta($post_id, 'customer_user', (int) $_POST['customer_user']); // Order items $order_items = array(); if (isset($_POST['item_id'])) { $item_id = $_POST['item_id']; $item_variation = $_POST['item_variation_id']; $item_name = $_POST['item_name']; $item_quantity = $_POST['item_quantity']; $item_cost = $_POST['item_cost']; $item_tax_rate = $_POST['item_tax_rate']; for ($i = 0; $i < count($item_id); $i++) { if (!isset($item_id[$i]) || !isset($item_name[$i]) || !isset($item_quantity[$i]) || !isset($item_cost[$i]) || !isset($item_tax_rate[$i])) { continue; } $variation_id = ''; $variation = ''; if (!empty($item_variation[$i])) { $variation_id = (int) $item_variation[$i]; // if this is a variation, we should check if it is an old one // and copy the 'variation' field describing details of variation foreach ($old_order_items as $old_item_index => $old_item) { if ($old_item['variation_id'] == $variation_id) { $variation = $old_item['variation']; unset($old_order_items[$old_item_index]); break; } } // override variation with values from $_POST if (isset($_POST['order_attributes'][$i]) && is_array($_POST['order_attributes'][$i])) { foreach ($_POST['order_attributes'][$i] as $var_key => $var_value) { $variation[$var_key] = $var_value; } } } $cost_inc_tax = $fflcommerce_options->get('fflcommerce_prices_include_tax') == 'yes' ? number_format((double) fflcommerce_clean($item_cost[$i]), 2, '.', '') : -1; $order_items[] = apply_filters('update_order_item', array('id' => htmlspecialchars(stripslashes($item_id[$i])), 'variation_id' => $variation_id, 'variation' => $variation, 'name' => htmlspecialchars(stripslashes($item_name[$i])), 'qty' => (int) $item_quantity[$i], 'cost' => number_format((double) fflcommerce_clean($item_cost[$i]), 2, '.', ''), 'cost_inc_tax' => $cost_inc_tax, 'taxrate' => number_format((double) fflcommerce_clean($item_tax_rate[$i]), 4, '.', ''))); } } // Save update_post_meta($post_id, 'order_data', $data); update_post_meta($post_id, 'order_items', $order_items); // Order status $order->update_status($_POST['order_status']); // Handle button actions if (isset($_POST['reduce_stock']) && $_POST['reduce_stock'] && count($order_items) > 0) { $order->add_order_note(__('Manually reducing stock.', 'fflcommerce')); foreach ($order_items as $order_item) { $_product = $order->get_product_from_item($order_item); if ($_product->exists) { if ($_product->managing_stock()) { $old_stock = $_product->stock; $new_quantity = $_product->reduce_stock($order_item['qty']); $order->add_order_note(sprintf(__('Item #%s stock reduced from %s to %s.', 'fflcommerce'), $order_item['id'], $old_stock, $new_quantity)); if ($new_quantity < 0) { if ($old_stock < 0) { $backorder_qty = $order_item['qty']; } else { $backorder_qty = $old_stock - $order_item['qty']; } do_action('fflcommerce_product_on_backorder_notification', $post_id, $_product, $backorder_qty); } // stock status notifications if ($fflcommerce_options->get('fflcommerce_notify_no_stock') == 'yes' && $fflcommerce_options->get('fflcommerce_notify_no_stock_amount') >= 0 && $fflcommerce_options->get('fflcommerce_notify_no_stock_amount') >= $new_quantity) { do_action('fflcommerce_no_stock_notification', $_product); } else { if ($fflcommerce_options->get('fflcommerce_notify_low_stock') == 'yes' && $fflcommerce_options->get('fflcommerce_notify_low_stock_amount') >= $new_quantity) { do_action('fflcommerce_low_stock_notification', $_product); } } } } else { $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'fflcommerce'), $order_item['id'], $order_item['name'])); } } $order->add_order_note(__('Manual stock reduction complete.', 'fflcommerce')); } else { if (isset($_POST['restore_stock']) && $_POST['restore_stock'] && sizeof($order_items) > 0) { $order->add_order_note(__('Manually restoring stock.', 'fflcommerce')); foreach ($order_items as $order_item) { $_product = $order->get_product_from_item($order_item); if ($_product->exists) { if ($_product->managing_stock()) { $old_stock = $_product->stock; $new_quantity = $_product->increase_stock($order_item['qty']); $order->add_order_note(sprintf(__('Item #%s stock increased from %s to %s.', 'fflcommerce'), $order_item['id'], $old_stock, $new_quantity)); } } else { $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'fflcommerce'), $order_item['id'], $order_item['name'])); } } $order->add_order_note(__('Manual stock restore complete.', 'fflcommerce')); } else { if (isset($_POST['invoice']) && $_POST['invoice']) { // Mail link to customer fflcommerce_send_customer_invoice($order->id); } } } // Error Handling if (count($fflcommerce_errors) > 0) { $fflcommerce_options->set('fflcommerce_errors', $fflcommerce_errors); } }
/** * When Options are saved, return the 'fflcommerce_tax_rates' option values * * @return mixed false if not rax rates, array of tax rates otherwise * @since 1.3 */ function get_updated_tax_classes() { $tax_rates = array(); $tax_fields = array('tax_classes' => '', 'tax_country' => '', 'tax_rate' => '', 'tax_label' => '', 'tax_shipping' => '', 'tax_compound' => ''); /* Save each array key to a variable */ foreach ($tax_fields as $name => $val) { if (isset($_POST[$name])) { $tax_fields[$name] = $_POST[$name]; } } for ($i = 0; $i < sizeof($tax_fields['tax_classes']); $i++) { if (empty($tax_fields['tax_rate'][$i])) { continue; } $countries = $tax_fields['tax_country'][$i]; $label = trim($tax_fields['tax_label'][$i]); $rate = number_format(floatval($tax_fields['tax_rate'][$i]), 4); $class = fflcommerce_clean($tax_fields['tax_classes'][$i]); $shipping = !empty($tax_fields['tax_shipping'][$i]) ? 'yes' : 'no'; $compound = !empty($tax_fields['tax_compound'][$i]) ? 'yes' : 'no'; /* Save the state & country separately from options eg US:OH */ $whole_countries_processed = array(); foreach ($countries as $country_code) { @(list($country, $state) = explode(':', $country_code, 2)); if (!in_array($country, $whole_countries_processed)) { if ($state === null && fflcommerce_countries::country_has_states($country)) { $whole_countries_processed[] = $country; foreach (fflcommerce_countries::get_states($country) as $state => $state_name) { $tax_rates[] = array('country' => $country, 'label' => $label, 'state' => $state, 'rate' => $rate, 'shipping' => $shipping, 'class' => $class, 'compound' => $compound, 'is_all_states' => true); } } else { $tax_rates[] = array('country' => $country, 'label' => $label, 'state' => $state, 'rate' => $rate, 'shipping' => $shipping, 'class' => $class, 'compound' => $compound, 'is_all_states' => false); } } } } usort($tax_rates, array($this, 'csort_tax_rates')); return $tax_rates; }
$posting['wp_remote_post']['note'] .= ' ' . sprintf(__('Status code: %s', 'fflcommerce'), fflcommerce_clean($response['response']['code'])); } $posting['wp_remote_post']['success'] = false; } // WP Remote Get Check $posting['wp_remote_get']['name'] = __('Remote Get', 'fflcommerce'); $posting['wp_remote_get']['help'] = '<a href="#" class="help_tip" data-tip="' . esc_attr__('FFL Commerce plugins may use this method of communication when checking for plugin updates.', 'fflcommerce') . '">[?]</a>'; $response = wp_remote_get('http://www.woothemes.com/wc-api/product-key-api?request=ping&network=' . (is_multisite() ? '1' : '0')); if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) { $posting['wp_remote_get']['success'] = true; } else { $posting['wp_remote_get']['note'] = __('wp_remote_get() failed. The fflcommerce plugin updater won\'t work with your server. Contact your hosting provider.', 'fflcommerce'); if (is_wp_error($response)) { $posting['wp_remote_get']['note'] .= ' ' . sprintf(__('Error: %s', 'fflcommerce'), fflcommerce_clean($response->get_error_message())); } else { $posting['wp_remote_get']['note'] .= ' ' . sprintf(__('Status code: %s', 'fflcommerce'), fflcommerce_clean($response['response']['code'])); } $posting['wp_remote_get']['success'] = false; } $posting = apply_filters('fflcommerce_debug_posting', $posting); foreach ($posting as $post) { $mark = !empty($post['success']) ? 'yes' : 'error'; ?> <tr> <td data-export-label="<?php echo esc_html($post['name']); ?> "><?php echo esc_html($post['name']); ?> :</td>
function fflcommerce_update_coupons() { /* Only grabbing this so as not to override the 'usage' field for a coupon when saving settings */ $original_coupons = get_option('fflcommerce_coupons'); $couponFields = array('coupon_code' => '', 'coupon_type' => '', 'coupon_amount' => '', 'usage_limit' => '', 'product_ids' => '', 'exclude_product_ids' => '', 'exclude_categories' => '', 'coupon_category' => '', 'coupon_date_from' => '', 'coupon_date_to' => '', 'individual' => '', 'coupon_free_shipping' => '', 'coupon_pay_methods' => '', 'order_total_min' => '', 'order_total_max' => ''); $coupons = array(); /* Save each array key to a variable */ foreach ($couponFields as $name => $val) { if (isset($_POST[$name])) { $couponFields[$name] = $_POST[$name]; } } extract($couponFields); for ($i = 0; $i < sizeof($coupon_code); $i++) { if (empty($coupon_code[$i]) || !is_numeric($coupon_amount[$i])) { continue; } $amount = fflcommerce_clean($coupon_amount[$i]); $code = fflcommerce_clean($coupon_code[$i]); $type = fflcommerce_clean($coupon_type[$i]); $limit = !empty($usage_limit[$i]) ? $usage_limit[$i] : 0; $min_order = !empty($order_total_min[$i]) ? $order_total_min[$i] : 0; $max_order = !empty($order_total_max[$i]) ? $order_total_max[$i] : 0; $from_date = !empty($coupon_date_from[$i]) ? strtotime($coupon_date_from[$i]) : 0; $free_ship = !empty($coupon_free_shipping[$i]) ? 'yes' : 'no'; $individual_use = !empty($individual[$i]) ? 'yes' : 'no'; $payments = !empty($coupon_pay_methods[$i]) ? $coupon_pay_methods[$i] : array(); $category = !empty($coupon_category[$i]) ? $coupon_category[$i] : array(); $products = !empty($product_ids[$i]) ? $product_ids[$i] : array(); $ex_products = !empty($exclude_product_ids[$i]) ? $exclude_product_ids[$i] : array(); $ex_categories = !empty($exclude_categories[$i]) ? $exclude_categories[$i] : array(); $to_date = !empty($coupon_date_to[$i]) ? strtotime($coupon_date_to[$i]) + (60 * 60 * 24 - 1) : 0; if ($code && $type && $amount) { $coupons[$code] = array('code' => $code, 'amount' => $amount, 'type' => $type, 'products' => $products, 'exclude_products' => $ex_products, 'exclude_categories' => $ex_categories, 'coupon_pay_methods' => $payments, 'coupon_category' => $category, 'date_from' => $from_date, 'date_to' => $to_date, 'individual_use' => $individual_use, 'coupon_free_shipping' => $free_ship, 'usage_limit' => $limit, 'order_total_min' => $min_order, 'order_total_max' => $max_order, 'usage' => !empty($original_coupons[$code]['usage']) ? $original_coupons[$code]['usage'] : 0); } } update_option('fflcommerce_coupons', $coupons); }
function fflcommerce_process_shop_coupon_meta($post_id, $post) { global $wpdb, $fflcommerce_errors; $type = fflcommerce_clean($_POST['type']); $amount = abs(fflcommerce_clean($_POST['amount'])); if (!empty($_POST['date_from'])) { $coupon_date_from = strtotime(fflcommerce_clean($_POST['date_from'])); } else { $coupon_date_from = ''; } if (!empty($_POST['date_to'])) { $coupon_date_to = strtotime(fflcommerce_clean($_POST['date_to'])) + (60 * 60 * 24 - 1); } else { $coupon_date_to = ''; } $usage_limit = isset($_POST['usage_limit']) && $_POST['usage_limit'] > 0 ? (int) fflcommerce_clean($_POST['usage_limit']) : ''; $individual = isset($_POST['individual_use']); $free_shipping = isset($_POST['free_shipping']); $minimum_amount = fflcommerce_clean($_POST['order_total_min']); $maximum_amount = fflcommerce_clean($_POST['order_total_max']); if (isset($_POST['include_products'])) { $include_products = fflcommerce_clean($_POST['include_products']); if ($include_products == 'Array') { $include_products = ''; } $include_products = $include_products != '' ? explode(',', $include_products) : array(); } else { $include_products = array(); } if (isset($_POST['exclude_products'])) { $exclude_products = fflcommerce_clean($_POST['exclude_products']); if ($exclude_products == 'Array') { $exclude_products = ''; } $exclude_products = $exclude_products != '' ? explode(',', $exclude_products) : array(); } else { $exclude_products = array(); } if (isset($_POST['include_categories'])) { $include_categories = $_POST['include_categories']; } else { $include_categories = array(); } if (isset($_POST['exclude_categories'])) { $exclude_categories = $_POST['exclude_categories']; } else { $exclude_categories = array(); } if (isset($_POST['pay_methods'])) { $pay_methods = $_POST['pay_methods']; } else { $pay_methods = array(); } update_post_meta($post_id, 'type', $type); update_post_meta($post_id, 'amount', $amount); update_post_meta($post_id, 'date_from', $coupon_date_from); update_post_meta($post_id, 'date_to', $coupon_date_to); update_post_meta($post_id, 'usage_limit', $usage_limit); update_post_meta($post_id, 'individual_use', $individual); update_post_meta($post_id, 'free_shipping', $free_shipping); update_post_meta($post_id, 'order_total_min', $minimum_amount); update_post_meta($post_id, 'order_total_max', $maximum_amount); update_post_meta($post_id, 'include_products', $include_products); update_post_meta($post_id, 'exclude_products', $exclude_products); update_post_meta($post_id, 'include_categories', $include_categories); update_post_meta($post_id, 'exclude_categories', $exclude_categories); update_post_meta($post_id, 'pay_methods', $pay_methods); }