Exemplo n.º 1
0
							<td>' . $item['qty'] . '</td>
							<td>' . fflcommerce_price($item['cost']) . '</td>
						</tr>';
    }
}
?>
        </tbody>
    </table>

    <div id="payment">
        <?php 
if ($order->order_total > 0) {
    ?>
            <ul class="payment_methods methods">
                <?php 
    $available_gateways = fflcommerce_payment_gateways::get_available_payment_gateways();
    if ($available_gateways) {
        // Chosen Method
        if (sizeof($available_gateways)) {
            current($available_gateways)->set_current();
        }
        foreach ($available_gateways as $gateway) {
            ?>
                        <li>
                            <input type="radio" id="payment_method_<?php 
            echo $gateway->id;
            ?>
" class="input-radio" name="payment_method" value="<?php 
            echo esc_attr($gateway->id);
            ?>
" <?php 
 /**
  * Process the checkout after the confirm order button is pressed
  */
 public function process_checkout()
 {
     if (!defined('FFLCOMMERCE_CHECKOUT')) {
         define('FFLCOMMERCE_CHECKOUT', true);
     }
     // Initialize cart
     fflcommerce_cart::get_cart();
     fflcommerce_cart::calculate_totals();
     if (isset($_POST) && $_POST && !isset($_POST['login'])) {
         fflcommerce::verify_nonce('process_checkout');
         // this will fill in our $posted array with validated data
         self::validate_checkout();
         $gateway = fflcommerce_payment_gateways::get_gateway($this->posted['payment_method']);
         if (self::process_gateway($gateway)) {
             $gateway->validate_fields();
         }
         do_action('fflcommerce_after_checkout_validation', $this->posted, $_POST, sizeof(fflcommerce::$errors));
         if (fflcommerce::has_errors()) {
             return false;
         }
         if (!isset($_POST['update_totals'])) {
             $user_id = get_current_user_id();
             // Create customer account and log them in
             if ($this->show_signup && !$user_id && $this->posted['create_account']) {
                 $user_id = $this->create_user_account();
                 if ($user_id === 0) {
                     return false;
                 }
             }
             $billing = array('first_name' => $this->posted['billing_first_name'], 'last_name' => $this->posted['billing_last_name'], 'company' => $this->posted['billing_company'], 'address_1' => $this->posted['billing_address_1'], 'address_2' => $this->posted['billing_address_2'], 'city' => $this->posted['billing_city'], 'state' => $this->posted['billing_state'], 'postcode' => $this->posted['billing_postcode'], 'country' => $this->posted['billing_country'], 'phone' => $this->posted['billing_phone'], 'email' => $this->posted['billing_email']);
             fflcommerce_customer::set_country($billing['country']);
             fflcommerce_customer::set_state($billing['state']);
             fflcommerce_customer::set_postcode($billing['postcode']);
             if (isset($this->posted['billing_euvatno']) && $this->valid_euvatno) {
                 $billing['euvatno'] = $this->posted['billing_euvatno'];
                 $billing['euvatno'] = str_replace(' ', '', $billing['euvatno']);
                 // If country code is not provided - add one.
                 if (strpos($billing['euvatno'], $billing['country']) === false) {
                     $billing['euvatno'] = $billing['country'] . $billing['euvatno'];
                 }
             }
             // Get shipping/billing
             if (!empty($this->posted['shiptobilling'])) {
                 $shipping = $billing;
                 unset($shipping['phone'], $shipping['email']);
             } elseif (fflcommerce_shipping::is_enabled()) {
                 $shipping = array('first_name' => $this->posted['shipping_first_name'], 'last_name' => $this->posted['shipping_last_name'], 'company' => $this->posted['shipping_company'], 'address_1' => $this->posted['shipping_address_1'], 'address_2' => $this->posted['shipping_address_2'], 'city' => $this->posted['shipping_city'], 'state' => $this->posted['shipping_state'], 'postcode' => $this->posted['shipping_postcode'], 'country' => $this->posted['shipping_country']);
             }
             fflcommerce_customer::set_shipping_country($shipping['country']);
             fflcommerce_customer::set_shipping_state($shipping['state']);
             fflcommerce_customer::set_shipping_postcode($shipping['postcode']);
             // Update totals based on processed customer address
             fflcommerce_cart::calculate_totals();
             // Save billing/shipping to user meta fields
             if ($user_id > 0) {
                 foreach ($billing as $field => $value) {
                     update_user_meta($user_id, 'billing_' . $field, $value);
                 }
                 if (isset($shipping)) {
                     foreach ($shipping as $field => $value) {
                         update_user_meta($user_id, 'shipping_' . $field, $value);
                     }
                 }
             }
             if (!isset($_POST['submit_action']) || $_POST['submit_action'] != 'place_order') {
                 $result = fflcommerce::redirect(fflcommerce_get_page_id(FFLCOMMERCE_CHECKOUT));
                 return array('result' => 'redirect', 'redirect' => $result);
             }
             // Order meta data
             $data = array();
             $applied_coupons = array_map(function ($coupon) {
                 return JS_Coupons::get_coupon($coupon);
             }, fflcommerce_cart::get_coupons());
             do_action('fflcommerce_checkout_update_order_total', $this->posted);
             foreach ($billing as $field => $value) {
                 $data['billing_' . $field] = $value;
             }
             if (isset($shipping)) {
                 foreach ($shipping as $field => $value) {
                     $data['shipping_' . $field] = $value;
                 }
             }
             $data['order_discount_coupons'] = $applied_coupons;
             $data['shipping_method'] = $this->posted['shipping_method'];
             $data['shipping_service'] = $this->posted['shipping_service'];
             $data['payment_method'] = $this->posted['payment_method'];
             $data['payment_method_title'] = $gateway->title;
             $data['order_subtotal'] = fflcommerce_cart::get_subtotal();
             $data['order_discount_subtotal'] = fflcommerce_cart::get_discount_subtotal();
             $data['order_shipping'] = fflcommerce_cart::get_shipping_total();
             $data['order_discount'] = fflcommerce_cart::get_total_discount(false);
             $data['order_tax'] = fflcommerce_cart::get_taxes_as_string();
             $data['order_tax_no_shipping_tax'] = fflcommerce_cart::get_total_cart_tax_without_shipping_tax();
             $data['order_tax_divisor'] = fflcommerce_cart::get_tax_divisor();
             $data['order_shipping_tax'] = fflcommerce_cart::get_shipping_tax();
             $data['order_total'] = fflcommerce_cart::get_total(false);
             $data['order_total_prices_per_tax_class_ex_tax'] = fflcommerce_cart::get_price_per_tax_class_ex_tax();
             if ($this->valid_euvatno) {
                 $data['order_tax'] = '';
                 $temp = fflcommerce_cart::get_total_cart_tax_without_shipping_tax();
                 $data['order_total'] -= $data['order_shipping_tax'] + $temp;
                 $data['order_shipping_tax'] = 0;
             }
             // Cart items
             $order_items = array();
             foreach (fflcommerce_cart::get_cart() as $values) {
                 /** @var fflcommerce_product $product */
                 $product = $values['data'];
                 // Check stock levels
                 if (!$product->has_enough_stock($values['quantity'])) {
                     fflcommerce::add_error(sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. Please edit your cart and try again. We apologize for any inconvenience caused.', 'fflcommerce'), $product->get_title()));
                     if (self::get_options()->get('fflcommerce_show_stock') == 'yes') {
                         fflcommerce::add_error(sprintf(__('We have only %d available at this time.', 'fflcommerce'), $product->get_stock()));
                     }
                     break;
                 }
                 // Calc item tax to store
                 $rates = $product->get_tax_destination_rate();
                 $rates = current($rates);
                 if (isset($rates['rate'])) {
                     $rate = $rates['rate'];
                 } else {
                     $rate = 0.0;
                 }
                 if ($this->valid_euvatno) {
                     $rate = 0.0;
                 }
                 $price_inc_tax = $product->get_price_with_tax();
                 if (!empty($values['variation_id'])) {
                     $product_id = $values['variation_id'];
                 } else {
                     $product_id = $values['product_id'];
                 }
                 $custom_products = (array) fflcommerce_session::instance()->customized_products;
                 $custom = isset($custom_products[$product_id]) ? $custom_products[$product_id] : '';
                 if (!empty($custom)) {
                     unset($custom_products[$product_id]);
                     fflcommerce_session::instance()->customized_products = $custom_products;
                 }
                 $order_items[] = apply_filters('new_order_item', array('id' => $values['product_id'], 'variation_id' => $values['variation_id'], 'variation' => $values['variation'], 'customization' => $custom, 'name' => $product->get_title(), 'qty' => (int) $values['quantity'], 'cost' => $product->get_price_excluding_tax(), 'cost_inc_tax' => $price_inc_tax, 'taxrate' => $rate), $values);
             }
             if (fflcommerce::has_errors()) {
                 return false;
             }
             // Insert or update the post data
             $create_new_order = true;
             $order_data = array('post_type' => 'shop_order', 'post_title' => 'Order &ndash; ' . date('F j, Y @ h:i A'), 'post_status' => 'publish', 'post_excerpt' => $this->posted['order_comments'], 'post_author' => 1);
             $order_id = 0;
             if (isset(fflcommerce_session::instance()->order_awaiting_payment) && fflcommerce_session::instance()->order_awaiting_payment > 0) {
                 $order_id = absint(fflcommerce_session::instance()->order_awaiting_payment);
                 $terms = wp_get_object_terms($order_id, 'shop_order_status', array('fields' => 'slugs'));
                 $order_status = isset($terms[0]) ? $terms[0] : 'pending';
                 // Resume the unpaid order if its pending
                 if ($order_status == 'pending' || $order_status == 'failed') {
                     $create_new_order = false;
                     $order_data['ID'] = $order_id;
                     wp_update_post($order_data);
                 }
             }
             if ($create_new_order) {
                 $order_id = wp_insert_post($order_data);
             }
             if (is_wp_error($order_id) || $order_id === 0) {
                 fflcommerce::add_error(__('Error: Unable to create order. Please try again.', 'fflcommerce'));
                 return false;
             }
             // Update post meta
             update_post_meta($order_id, 'order_data', $data);
             update_post_meta($order_id, 'order_key', uniqid('order_'));
             update_post_meta($order_id, 'customer_user', (int) $user_id);
             update_post_meta($order_id, 'order_items', $order_items);
             wp_set_object_terms($order_id, 'pending', 'shop_order_status');
             $order = new fflcommerce_order($order_id);
             /* Coupon usage limit */
             foreach ($data['order_discount_coupons'] as $coupon) {
                 $coupon_id = JS_Coupons::get_coupon_post_id($coupon['code']);
                 if ($coupon_id !== false) {
                     $usage_count = get_post_meta($coupon_id, 'usage', true);
                     $usage_count = empty($usage_count) ? 1 : $usage_count + 1;
                     update_post_meta($coupon_id, 'usage', $usage_count);
                 }
             }
             if ($create_new_order) {
                 do_action('fflcommerce_new_order', $order_id);
             } else {
                 do_action('fflcommerce_resume_order', $order_id);
             }
             do_action('fflcommerce_checkout_update_order_meta', $order_id, $this->posted);
             // can't just simply check needs_payment() here, as paypal may have force payment set to true
             if (self::process_gateway($gateway)) {
                 // Store Order ID in session so it can be re-used after payment failure
                 fflcommerce_session::instance()->order_awaiting_payment = $order_id;
                 // Process Payment
                 $result = $gateway->process_payment($order_id);
                 // Redirect to success/confirmation/payment page
                 if ($result['result'] == 'success') {
                     return $result;
                 }
                 return false;
             } else {
                 // No payment was required for order
                 $order->payment_complete();
                 // Empty the Cart
                 fflcommerce_cart::empty_cart();
                 // Redirect to success/confirmation/payment page
                 $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks'));
                 return array('result' => 'redirect', 'redirect' => $checkout_redirect);
             }
         }
     }
     return true;
 }
Exemplo n.º 3
0
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;
        }
    }
}
    public function format_option_for_display($item)
    {
        $options = FFLCommerce_Base::get_options();
        if (!isset($item['id'])) {
            return '';
        }
        // ensure we have an id to work with
        $display = "";
        // each item builds it's output into this and it's returned for echoing
        $class = "";
        if (isset($item['class'])) {
            $class = $item['class'];
        }
        // display a tooltip if there is one in it's own table data element before the item to display
        $display .= '<td class="fflcommerce-tooltips">';
        if (!empty($item['tip'])) {
            $display .= '<a href="#" tip="' . esc_attr($item['tip']) . '" class="tips" tabindex="99"></a>';
        }
        $display .= '</td><td class="forminp">';
        $disabled = '';
        $disabledItems = array();
        if (isset($item['extra']) && isset($item['extra']['disabled'])) {
            if ($item['extra']['disabled'] === true) {
                $disabled = ' disabled';
            } else {
                if (is_array($item['extra']['disabled'])) {
                    $disabledItems = $item['extra']['disabled'];
                }
            }
        }
        /*
         *  work off the option type and format output for display for each type
         */
        switch ($item['type']) {
            case 'user_defined':
                if (isset($item['display'])) {
                    if (is_callable($item['display'], true)) {
                        $display .= call_user_func($item['display']);
                    }
                }
                break;
            case 'default_gateway':
                $id = $item['id'];
                $display .= '<select id="' . $id . '" class="fflcommerce-input fflcommerce-select ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $id . ']"' . $disabled . ' >';
                $gateways = fflcommerce_payment_gateways::get_available_payment_gateways();
                foreach ($gateways as $slug => $gateway) {
                    $display .= '<option value="' . esc_attr($slug) . '" ' . selected($options->get($id), $slug, false) . disabled(in_array($id, $disabledItems, false)) . ' />' . $gateway->title . '</option>';
                }
                $display .= '</select>';
                ?>
				<script type="text/javascript">
					/*<![CDATA[*/
					jQuery(function($){
						$("#<?php 
                echo $id;
                ?>
").select2({ width: '250px' });
					});
					/*]]>*/
				</script>
				<?php 
                break;
            case 'gateway_options':
                foreach (fflcommerce_payment_gateways::payment_gateways() as $gateway) {
                    $gateway->admin_options();
                }
                break;
            case 'shipping_options':
                foreach (fflcommerce_shipping::get_all_methods() as $shipping_method) {
                    $shipping_method->admin_options();
                }
                break;
            case 'tax_rates':
                $display .= $this->format_tax_rates_for_display($item);
                break;
            case 'single_select_page':
                $page_setting = (int) $options->get($item['id']);
                $args = array('name' => FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']', 'id' => $item['id'], 'sort_order' => 'ASC', 'echo' => 0, 'selected' => $page_setting);
                if (isset($item['extra'])) {
                    $args = wp_parse_args($item['extra'], $args);
                }
                $display .= wp_dropdown_pages($args);
                $parts = explode('<select', $display);
                $id = $item['id'];
                $display = $parts[0] . '<select id="' . $id . '" class="' . $class . '"' . $parts[1];
                ?>
				<script type="text/javascript">
					/*<![CDATA[*/
					jQuery(function($){
						$("#<?php 
                echo $id;
                ?>
").select2({ width: '250px' });
					});
					/*]]>*/
				</script>
				<?php 
                break;
            case 'single_select_country':
                $country_setting = (string) $options->get($item['id']);
                $add_empty = false;
                if (isset($item['options']['add_empty']) && $item['options']['add_empty']) {
                    $add_empty = true;
                }
                if (strstr($country_setting, ':')) {
                    $temp = explode(':', $country_setting);
                    $country = current($temp);
                    $state = end($temp);
                } else {
                    $country = $country_setting;
                    $state = '*';
                }
                $id = $item['id'];
                $display .= '<select id="' . $id . '" class="single_select_country ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"' . $disabled . '>';
                $display .= fflcommerce_countries::country_dropdown_options($country, $state, true, false, false, $add_empty);
                $display .= '</select>';
                ?>
				<script type="text/javascript">
					/*<![CDATA[*/
					jQuery(function($){
						$("#<?php 
                echo $id;
                ?>
").select2({ width: '500px' });
					});
					/*]]>*/
				</script>
				<?php 
                break;
            case 'multi_select_countries':
                $countries = fflcommerce_countries::get_countries();
                $selections = (array) $options->get($item['id']);
                $display .= '<select multiple="multiple" id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-select ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . '][]"' . $disabled . '>';
                foreach ($countries as $key => $val) {
                    $display .= '<option value="' . esc_attr($key) . '" ' . selected(in_array($key, $selections), true, false) . disabled(in_array($key, $disabledItems, false)) . ' />' . $val . '</option>';
                }
                $display .= '</select>';
                $id = $item['id'];
                ?>
				<script type="text/javascript">
					/*<![CDATA[*/
					jQuery(function($){
						$("#<?php 
                echo $id;
                ?>
").select2({ width: '500px' });
					});
					/*]]>*/
				</script>
				<?php 
                break;
            case 'button':
                if (isset($item['extra'])) {
                    $display .= '<a id="' . $item['id'] . '" class="button ' . $class . '" href="' . esc_attr($item['extra']) . '">' . esc_attr($item['desc']) . '</a>';
                }
                $item['desc'] = '';
                // temporarily remove it so it doesn't display twice
                break;
            case 'decimal':
                // decimal numbers are positive or negative 0-9 inclusive, may include decimal
                $display .= '<input	id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"
					type="number" step="any" size="20" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'integer':
                // integer numbers are positive or negative 0-9 inclusive
            // integer numbers are positive or negative 0-9 inclusive
            case 'natural':
                // natural numbers are positive 0-9 inclusive
                $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"
					type="number" size="20" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'text':
                // any character sequence
                $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"
					type="text" size="20" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'midtext':
                $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"
					type="text" size="40" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'longtext':
                $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"
					type="text" size="80" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'email':
                $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-text fflcommerce-email ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"
					type="text" size="40" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'codeblock':
            case 'textarea':
                $cols = '60';
                if (isset($item['choices'])) {
                    $ta_options = $item['choices'];
                    if (isset($ta_options['cols'])) {
                        $cols = $ta_options['cols'];
                    }
                }
                $ta_value = stripslashes($options->get($item['id']));
                $display .= '<textarea id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-textarea ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" cols="' . $cols . '" rows="4"' . $disabled . '>' . esc_textarea($ta_value) . '</textarea>';
                break;
            case "radio":
                // default to horizontal display of choices ( 'horizontal' may or may not be defined )
                if (!isset($item['extra']) || !in_array('vertical', $item['extra'])) {
                    $display .= '<div class="fflcommerce-radio-horz">';
                    foreach ($item['choices'] as $option => $name) {
                        $display .= '<input class="fflcommerce-input fflcommerce-radio ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"
							id="' . $item['id'] . '[' . $option . ']" type="radio" value="' . $option . '" ' . checked($options->get($item['id']), $option, false) . disabled(in_array($option, $disabledItems), true, false) . '
							/><label for="' . $item['id'] . '[' . $option . ']">' . $name . '</label>';
                    }
                    $display .= '</div>';
                } else {
                    if (isset($item['extra']) && in_array('vertical', $item['extra'])) {
                        $display .= '<ul class="fflcommerce-radio-vert">';
                        foreach ($item['choices'] as $option => $name) {
                            $display .= '<li><input class="fflcommerce-input fflcommerce-radio ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"
							id="' . $item['id'] . '[' . $option . ']" type="radio" value="' . $option . '" ' . checked($options->get($item['id']), $option, false) . disabled(in_array($option, $disabledItems), true, false) . '
							/><label for="' . $item['id'] . '[' . $option . ']">' . $name . '</label></li>';
                        }
                        $display .= '</ul>';
                    }
                }
                break;
            case 'checkbox':
                $display .= '<span class="fflcommerce-container"><input id="' . $item['id'] . '" type="checkbox" class="fflcommerce-input fflcommerce-checkbox ' . $class . '"
					name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" ' . checked($options->get($item['id']), 'yes', false) . $disabled . '
					/><label for="' . $item['id'] . '">' . $item['name'] . '</label></span>';
                break;
            case 'multicheck':
                $multi_stored = $options->get($item['id']);
                // default to horizontal display of choices ( 'horizontal' may or may not be defined )
                if (!isset($item['extra']) || !in_array('vertical', $item['extra'])) {
                    $display .= '<div class="fflcommerce-multi-checkbox-horz ' . $class . '">';
                    foreach ($item['choices'] as $key => $option) {
                        $display .= '<input id="' . $item['id'] . '_' . $key . '" class="fflcommerce-input" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . '][' . $key . ']"
							type="checkbox" ' . checked($multi_stored[$key], true, false) . disabled(in_array($key, $disabledItems, false)) . ' /> <label for="' . $item['id'] . '_' . $key . '">' . $option . '</label>';
                    }
                    $display .= '</div>';
                } else {
                    if (isset($item['extra']) && in_array('vertical', $item['extra'])) {
                        $display .= '<ul class="fflcommerce-multi-checkbox-vert ' . $class . '">';
                        foreach ($item['choices'] as $key => $option) {
                            $display .= '<li><input id="' . $item['id'] . '_' . $key . '" class="fflcommerce-input" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . '][' . $key . ']"
							type="checkbox" ' . checked($multi_stored[$key], true, false) . disabled(in_array($key, $disabledItems, false)) . ' /> <label for="' . $item['id'] . '_' . $key . '">' . $option . '</label></li>';
                        }
                        $display .= '</ul>';
                    }
                }
                break;
            case 'range':
                $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-range ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']"
					type="range" min="' . $item['extra']['min'] . '" max="' . $item['extra']['max'] . '" step="' . $item['extra']['step'] . '"
					value="' . $options->get($item['id']) . '"' . $disabled . ' />';
                break;
            case 'number':
                $display .= '<input id="' . $item['id'] . '" class="fflcommerce-input ' . $class . '" name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']" type="number" value="' . $options->get($item['id']) . '"';
                if (isset($item['extra']['min'])) {
                    $display .= ' min="' . $item['extra']['min'] . '"';
                }
                if (isset($item['extra']['max'])) {
                    $display .= ' max="' . $item['extra']['max'] . '"';
                }
                if (isset($item['extra']['step'])) {
                    $display .= ' step="' . $item['extra']['step'] . '"';
                }
                $display .= $disabled . ' />';
                break;
            case 'select':
                $multiple = !empty($item['multiple']) && $item['multiple'] == true ? 'multiple="multiple"' : "";
                $brckt = "";
                $width = 250;
                $selections = (array) $options->get($item['id']);
                if ($item['multiple']) {
                    $brckt = "[]";
                    $width = 500;
                }
                $display .= '<select id="' . $item['id'] . '" class="fflcommerce-input fflcommerce-select ' . $class . '"
					name="' . FFLCOMMERCE_OPTIONS . '[' . $item['id'] . ']' . $brckt . '"' . $multiple . $disabled . ' >';
                foreach ($item['choices'] as $value => $label) {
                    if (is_array($label)) {
                        $display .= '<optgroup label="' . $value . '">';
                        foreach ($label as $subValue => $subLabel) {
                            $display .= '<option value="' . esc_attr($subValue) . '" ' . selected(in_array(esc_attr($subValue), $selections), true, false) . disabled(in_array($subValue, $disabledItems), true, false) . ' />' . $subLabel . '</option>';
                        }
                        $display .= '</optgroup>';
                    } else {
                        $display .= '<option value="' . esc_attr($value) . '" ' . selected(in_array(esc_attr($value), $selections), true, false) . disabled(in_array($value, $disabledItems), true, false) . ' />' . $label . '</option>';
                    }
                }
                $display .= '</select>';
                $id = $item['id'];
                ?>
				<script type="text/javascript">
					/*<![CDATA[*/
					jQuery(function($){
						$("#<?php 
                echo $id;
                ?>
").select2({ width: '<?php 
                echo $width;
                ?>
px' });
					});
					/*]]>*/
				</script>
				<?php 
                break;
            default:
                fflcommerce_log("UNKOWN _type_ in Options parsing");
                fflcommerce_log($item);
        }
        if ($item['type'] != 'tab') {
            if (empty($item['desc'])) {
                $explain_value = '';
            } else {
                $explain_value = $item['desc'];
            }
            $display .= '<div class="fflcommerce-explain"><small>' . $explain_value . '</small></div></td>';
        }
        return $display;
    }
Exemplo n.º 5
0
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);
    }
}
Exemplo n.º 6
0
/**
 * Outputs the thankyou page
 **/
function fflcommerce_thankyou()
{
    $thankyou_message = __('<p>Thank you. Your order has been processed successfully.</p>', 'fflcommerce');
    echo apply_filters('fflcommerce_thankyou_message', $thankyou_message);
    // 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) {
            ?>
			<?php 
            do_action('fflcommerce_thankyou_before_order_details', $order->id);
            ?>
			<ul class="order_details">
				<li class="order">
					<?php 
            _e('Order:', 'fflcommerce');
            ?>
					<strong><?php 
            echo $order->get_order_number();
            ?>
</strong>
				</li>
				<li class="date">
					<?php 
            _e('Date:', 'fflcommerce');
            ?>
					<strong><?php 
            echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($order->order_date));
            ?>
</strong>
				</li>
				<li class="total">
					<?php 
            _e('Total:', 'fflcommerce');
            ?>
					<strong><?php 
            echo fflcommerce_price($order->order_total);
            ?>
</strong>
				</li>
				<li class="method">
					<?php 
            _e('Payment method:', 'fflcommerce');
            ?>
					<strong><?php 
            $gateways = fflcommerce_payment_gateways::payment_gateways();
            if (isset($gateways[$order->payment_method])) {
                echo $gateways[$order->payment_method]->title;
            } else {
                echo $order->payment_method;
            }
            ?>
</strong>
				</li>
			</ul>
			<div class="clear"></div>
			<?php 
            do_action('thankyou_' . $order->payment_method, $order_id);
            do_action('fflcommerce_thankyou', $order->id);
        }
    }
    echo '<p><a class="button" href="' . esc_url(fflcommerce_cart::get_shop_url()) . '">' . __('&larr; Continue Shopping', 'fflcommerce') . '</a></p>';
}
Exemplo n.º 7
0
/**
 * Order totals meta box
 *
 * Displays the order totals meta box
 *
 * @since 		1.0
 */
function fflcommerce_order_totals_meta_box($post)
{
    $_order = new fflcommerce_order($post->ID);
    $coupons = array();
    $order_discount_coupons = (array) $_order->_fetch('order_discount_coupons');
    if (!empty($order_discount_coupons)) {
        foreach ($order_discount_coupons as $coupon) {
            $coupons[] = isset($coupon['code']) ? $coupon['code'] : '';
        }
    }
    ?>
	<ul class="totals">
		<li class="left">
			<label><?php 
    _e('Subtotal:', 'fflcommerce');
    ?>
</label>
			<input type="text" id="order_subtotal" name="order_subtotal" placeholder="0.00 <?php 
    _e('(ex. tax)', 'fflcommerce');
    ?>
" value="<?php 
    echo esc_attr($_order->_fetch('order_subtotal'));
    ?>
" class="first" />
		</li>

		<li class="right">
			<label><?php 
    _e('Discount: ', 'fflcommerce');
    ?>
<span class="applied-coupons-values"><?php 
    echo implode(',', $coupons);
    ?>
</span></label>
			<input type="text" id="order_discount" name="order_discount" placeholder="0.00" value="<?php 
    echo esc_attr($_order->_fetch('order_discount'));
    ?>
" />
		</li>
		<?php 
    $shipping_methods = fflcommerce_shipping::get_all_methods();
    $shipping_select = "<select id='shipping_method' name='shipping_method' class='last' data-placeholder=" . __('Choose', 'fflcommerce') . ">";
    $shipping_select .= "<option></option>";
    if (!empty($shipping_methods)) {
        foreach ($shipping_methods as $index => $method) {
            $mark = '';
            if ($_order->_fetch('shipping_method') == $method->id) {
                $mark = 'selected="selected"';
            }
            $shipping_select .= "<option value='{$method->id}' {$mark}>{$method->title}</option>";
        }
    }
    $shipping_select .= "</select>";
    ?>
		<li>
			<label><?php 
    _e('Shipping:', 'fflcommerce');
    ?>
</label>
            <input type="text" id="order_shipping" name="order_shipping" placeholder="0.00 <?php 
    _e('(ex. tax)', 'fflcommerce');
    ?>
" value="<?php 
    echo esc_attr($_order->_fetch('order_shipping'));
    ?>
" class="first" /> <?php 
    echo $shipping_select;
    ?>
			<script type="text/javascript">
				/*<![CDATA[*/
					jQuery(function() {
						jQuery("#shipping_method").select2({ width: '120px' });
					});
				/*]]>*/
			</script>
        </li>

		<li class="left">
			<label><?php 
    _e('Total Tax:', 'fflcommerce');
    ?>
</label>
			<input type="text" id="order_tax" name="order_tax_total" placeholder="0.00" value="<?php 
    echo esc_attr($_order->get_total_tax());
    ?>
" class="first" />
		</li>

		<li class="right">
			<label><?php 
    _e('Shipping Tax:', 'fflcommerce');
    ?>
</label>
			<input type="text" id="order_shipping_tax" name="order_shipping_tax" placeholder="0.00" value="<?php 
    echo esc_attr($_order->_fetch('order_shipping_tax'));
    ?>
" class="first" />
		</li>
		<?php 
    $payment_methods = fflcommerce_payment_gateways::get_available_payment_gateways();
    $payment_select = "<select id='payment_method' name='payment_method' class='last' data-placeholder=" . __('Choose', 'fflcommerce') . ">";
    $payment_select .= "<option></option>";
    if (!empty($payment_methods)) {
        foreach ($payment_methods as $index => $method) {
            $mark = '';
            if ($_order->_fetch('payment_method') == $method->id) {
                $mark = 'selected="selected"';
            }
            $payment_select .= "<option value='{$method->id}' {$mark}>{$method->title}</option>";
        }
    }
    $payment_select .= "</select>";
    ?>
		<?php 
    do_action('fflcommerce_admin_order_totals_after_shipping', $post->ID);
    ?>
		<li>
			<label><?php 
    _e('Total:', 'fflcommerce');
    ?>
</label>
            <input type="text" id="order_total" name="order_total" placeholder="0.00" value="<?php 
    echo esc_attr($_order->_fetch('order_total'));
    ?>
" class="first" /> <?php 
    echo $payment_select;
    ?>
			<script type="text/javascript">
				/*<![CDATA[*/
					jQuery(function() {
						jQuery("#payment_method").select2({ width: '120px' });
					});
				/*]]>*/
			</script>
		</li>

	</ul>
	<div class="clear"></div>
	<?php 
}
Exemplo n.º 8
0
function fflcommerce_init()
{
    // Override default translations with custom .mo's found in wp-content/languages/fflcommerce first.
    load_textdomain('fflcommerce', WP_LANG_DIR . '/fflcommerce/fflcommerce-' . get_locale() . '.mo');
    load_plugin_textdomain('fflcommerce', false, dirname(plugin_basename(__FILE__)) . '/languages/');
    add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'fflcommerce_admin_bar_links');
    // instantiate options -after- loading text domains
    $options = FFLCommerce_Base::get_options();
    fflcommerce_post_type();
    // register taxonomies
    new fflcommerce_cron();
    // -after- text domains and Options instantiation allows settings translations
    fflcommerce_set_image_sizes();
    // called -after- our Options are loaded
    // add Singletons here so that the taxonomies are loaded before calling them.
    fflcommerce_session::instance();
    // Start sessions if they aren't already
    fflcommerce::instance();
    // Utility functions, uses sessions
    fflcommerce_customer::instance();
    // Customer class, sorts session data such as location
    // FFL Commerce will instantiate gateways and shipping methods on this same 'init' action hook
    // with a very low priority to ensure text domains are loaded first prior to installing any external options
    fflcommerce_shipping::instance();
    // Shipping class. loads shipping methods
    fflcommerce_payment_gateways::instance();
    // Payment gateways class. loads payment methods
    fflcommerce_cart::instance();
    // Cart class, uses sessions
    add_filter('mce_external_plugins', 'fflcommerce_register_shortcode_editor');
    add_filter('mce_buttons', 'fflcommerce_register_shortcode_buttons');
    if (!is_admin()) {
        /* Catalog Filters */
        add_filter('loop-shop-query', create_function('', 'return array("orderby" => "' . $options->get('fflcommerce_catalog_sort_orderby') . '","order" => "' . $options->get('fflcommerce_catalog_sort_direction') . '");'));
        add_filter('loop_shop_columns', create_function('', 'return ' . $options->get('fflcommerce_catalog_columns') . ';'));
        add_filter('loop_shop_per_page', create_function('', 'return ' . $options->get('fflcommerce_catalog_per_page') . ';'));
        fflcommerce_catalog_query::instance();
        // front end queries class
        fflcommerce_request_api::instance();
        // front end request api for URL's
    }
    fflcommerce_roles_init();
    do_action('fflcommerce_initialize_plugins');
}
function fflcommerce_admin_option_display($options)
{
    if (empty($options)) {
        return false;
    }
    $counter = 1;
    foreach ($options as $value) {
        switch ($value['type']) {
            case 'string':
                ?>
<tr>
				<th scope="row"><?php 
                echo $value['name'];
                ?>
</th>
				<td><?php 
                echo $value['desc'];
                ?>
</td>
			  </tr><?php 
                break;
            case 'tab':
                ?>
<div id="<?php 
                echo $value['type'] . $counter;
                ?>
" class="panel">
			  <table class="form-table"><?php 
                break;
            case 'title':
                ?>
<thead>
				<tr>
					<th scope="col" colspan="2">
						<h3 class="title"><?php 
                echo $value['name'];
                ?>
</h3>
						<?php 
                if (!empty($value['desc'])) {
                    ?>
						<p><?php 
                    echo $value['desc'];
                    ?>
</p>
						<?php 
                }
                ?>
					</th>
				</tr>
			  </thead><?php 
                break;
            case 'button':
                ?>
<tr>
				<th scope="row"<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                if (!empty($value['tip'])) {
                    ?>
					<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99" ></a>
					<?php 
                }
                ?>
					<?php 
                if (!empty($value['name'])) {
                    ?>
					<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo $value['name'];
                    ?>
</label>
					<?php 
                }
                ?>
				</th>
				<td<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<a  id="<?php 
                echo esc_attr($value['id']);
                ?>
"
						class="button <?php 
                if (!empty($value['class'])) {
                    echo esc_attr($value['class']);
                }
                ?>
"
						style="<?php 
                if (!empty($value['css'])) {
                    echo esc_attr($value['css']);
                }
                ?>
"
						href="<?php 
                if (!empty($value['href'])) {
                    echo esc_attr($value['href']);
                }
                ?>
"
					><?php 
                if (!empty($value['desc'])) {
                    echo $value['desc'];
                }
                ?>
</a>
				</td>
			  </tr><?php 
                break;
            case 'checkbox':
                ?>
<tr>
				<th scope="row"<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                if (!empty($value['tip'])) {
                    ?>
					<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99" ></a>
					<?php 
                }
                ?>
					<?php 
                if (!empty($value['name'])) {
                    ?>
					<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo $value['name'];
                    ?>
</label>
					<?php 
                }
                ?>
				</th>
				<td<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<input
					id="<?php 
                echo esc_attr($value['id']);
                ?>
"
					type="checkbox"
					class="fflcommerce-input fflcommerce-checkbox <?php 
                if (!empty($value['class'])) {
                    echo esc_attr($value['class']);
                }
                ?>
"
					style="<?php 
                if (!empty($value['css'])) {
                    echo esc_attr($value['css']);
                }
                ?>
"
					name="<?php 
                echo esc_attr($value['id']);
                ?>
"
					<?php 
                if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
                    echo checked(get_option($value['id']), 'yes', false);
                } else {
                    if (isset($value['std'])) {
                        echo checked($value['std'], 'yes', false);
                    }
                }
                ?>
 />
					<label for="<?php 
                echo esc_attr($value['id']);
                ?>
"><?php 
                if (!empty($value['desc'])) {
                    echo $value['desc'];
                }
                ?>
</label>
				</td>
			  </tr><?php 
                break;
            case 'text':
            case 'number':
                ?>
<tr>
				<th scope="row"<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                if (!empty($value['tip'])) {
                    ?>
					<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a>
					<?php 
                }
                ?>
					<?php 
                if (!empty($value['name'])) {
                    ?>
					<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo $value['name'];
                    ?>
</label>
					<?php 
                }
                ?>
				</th>

				<td<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<input name="<?php 
                echo esc_attr($value['id']);
                ?>
"
						id="<?php 
                echo esc_attr($value['id']);
                ?>
"
						type="<?php 
                echo $value['type'];
                ?>
"
						<?php 
                if ($value['type'] == 'number' && !empty($value['restrict']) && is_array($value['restrict'])) {
                    ?>
						min="<?php 
                    echo isset($value['restrict']['min']) ? $value['restrict']['min'] : '';
                    ?>
"
						max="<?php 
                    echo isset($value['restrict']['max']) ? $value['restrict']['max'] : '';
                    ?>
"
						step="<?php 
                    echo isset($value['restrict']['step']) ? $value['restrict']['step'] : 'any';
                    ?>
"
						<?php 
                }
                ?>
						class="regular-text <?php 
                if (!empty($value['class'])) {
                    echo esc_attr($value['class']);
                }
                ?>
"
						style="<?php 
                if (!empty($value['css'])) {
                    echo esc_attr($value['css']);
                }
                ?>
"
						placeholder="<?php 
                if (!empty($value['placeholder'])) {
                    echo esc_attr($value['placeholder']);
                }
                ?>
"
						value="<?php 
                if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
                    echo esc_attr(get_option($value['id']));
                } else {
                    if (isset($value['std'])) {
                        echo esc_attr($value['std']);
                    }
                }
                ?>
" />
					<?php 
                if (!empty($value['desc']) && (!empty($value['name']) && empty($value['group']))) {
                    ?>
							<br /><small><?php 
                    echo $value['desc'];
                    ?>
</small>
					<?php 
                } elseif (!empty($value['desc'])) {
                    ?>
						<?php 
                    echo $value['desc'];
                    ?>
					<?php 
                }
                ?>
				</td>
			  </tr><?php 
                break;
            case 'select':
                ?>
<tr>
				<th scope="row"<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                if (!empty($value['tip'])) {
                    ?>
					<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a>
					<?php 
                }
                ?>
					<?php 
                if (!empty($value['name'])) {
                    ?>
					<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo $value['name'];
                    ?>
</label>
					<?php 
                }
                ?>
				</th>
				<td>
					<select name="<?php 
                echo esc_attr($value['id']);
                ?>
"
							id="<?php 
                echo esc_attr($value['id']);
                ?>
"
							style="<?php 
                if (isset($value['css'])) {
                    echo esc_attr($value['css']);
                }
                ?>
"
							class="<?php 
                if (!empty($value['class'])) {
                    echo esc_attr($value['class']);
                }
                ?>
"
							<?php 
                if (!empty($value['multiple'])) {
                    echo 'multiple="multiple"';
                }
                ?>
							<?php 
                if (!empty($value['class']) && $value['class'] == 'chzn-select' && !empty($value['placeholder'])) {
                    ?>
							data-placeholder="<?php 
                    _e(esc_attr($value['placeholder']));
                    ?>
"
							<?php 
                }
                ?>
					>

					<?php 
                $selected = get_option($value['id']);
                $selected = !empty($selected) ? $selected : $value['std'];
                ?>
					<?php 
                foreach ($value['options'] as $key => $val) {
                    ?>
						<option value="<?php 
                    echo esc_attr($key);
                    ?>
"
						<?php 
                    if (!is_array($selected) && $selected == $key || is_array($selected) && in_array($key, $selected)) {
                        ?>
								selected="selected"
						<?php 
                    }
                    ?>
						>
							<?php 
                    echo ucfirst($val);
                    ?>
						</option>
					<?php 
                }
                ?>
					</select>
					<?php 
                if (!empty($value['desc']) && (!empty($value['name']) && empty($value['group']))) {
                    ?>
						<br /><small><?php 
                    echo $value['desc'];
                    ?>
</small>
					<?php 
                } elseif (!empty($value['desc'])) {
                    ?>
						<?php 
                    echo $value['desc'];
                    ?>
					<?php 
                }
                ?>
				</td>
			  </tr><?php 
                break;
            case 'radio':
                ?>
<tr>
				<th scope="row"<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                if (!empty($value['tip'])) {
                    ?>
					<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a>
					<?php 
                }
                ?>
					<?php 
                echo $value['name'];
                ?>
				</th>
				<td<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                foreach ($value['options'] as $key => $val) {
                    ?>
					<label class="radio">
					<input type="radio"
						   name="<?php 
                    echo esc_attr($value['id']);
                    ?>
"
						   id="<?php 
                    echo esc_attr($key);
                    ?>
"
						   value="<?php 
                    echo esc_attr($key);
                    ?>
"
						   class="<?php 
                    if (!empty($value['class'])) {
                        echo esc_attr($value['class']);
                    }
                    ?>
"
						   <?php 
                    if (get_option($value['id']) == $key) {
                        ?>
 checked="checked" <?php 
                    }
                    ?>
>
					<?php 
                    echo esc_attr(ucfirst($val));
                    ?>
					</label><br />
					<?php 
                }
                ?>
				</td>
			  </tr><?php 
                break;
            case 'image_size':
                $sizes = array('fflcommerce_shop_tiny' => 'fflcommerce_use_wordpress_tiny_crop', 'fflcommerce_shop_thumbnail' => 'fflcommerce_use_wordpress_thumbnail_crop', 'fflcommerce_shop_small' => 'fflcommerce_use_wordpress_catalog_crop', 'fflcommerce_shop_large' => 'fflcommerce_use_wordpress_featured_crop');
                $altSize = $sizes[$value['id']];
                ?>
<tr>
				<th scope="row"><?php 
                echo $value['name'];
                ?>
</label></th>
				<td valign="top" style="line-height:25px;height:25px;">

					<input name="<?php 
                echo esc_attr($value['id']);
                ?>
_w"
						   id="<?php 
                echo esc_attr($value['id']);
                ?>
_w"
						   type="number"
						   min="0"
						   style="width:60px;"
						   placeholder=<?php 
                if (!empty($value['placeholder'])) {
                    echo $value['placeholder'];
                }
                ?>
						   value="<?php 
                if ($size = get_option($value['id'] . '_w')) {
                    echo $size;
                } else {
                    echo $value['std'];
                }
                ?>
"
					/>

					<label for="<?php 
                echo esc_attr($value['id']);
                ?>
_h">x</label>

					<input name="<?php 
                echo esc_attr($value['id']);
                ?>
_h"
						   id="<?php 
                echo esc_attr($value['id']);
                ?>
_h"
						   type="number"
						   min="0"
						   style="width:60px;"
						   placeholder=<?php 
                if (!empty($value['placeholder'])) {
                    echo $value['placeholder'];
                }
                ?>
						   value="<?php 
                if ($size = get_option($value['id'] . '_h')) {
                    echo $size;
                } else {
                    echo $value['std'];
                }
                ?>
"
					/>

					<input
					id="<?php 
                echo esc_attr($altSize);
                ?>
"
					type="checkbox"
					class="fflcommerce-input fflcommerce-checkbox"
					name="<?php 
                echo esc_attr($altSize);
                ?>
"
					<?php 
                if (get_option($altSize) !== false && get_option($altSize) !== null) {
                    echo checked(get_option($altSize), 'yes', false);
                }
                ?>
 />
					<label for="<?php 
                echo esc_attr($altSize);
                ?>
"> <?php 
                echo __('Crop', 'fflcommerce');
                ?>
</label>
					<br /><small><?php 
                echo $value['desc'];
                ?>
</small>
				</td>
			</tr><?php 
                break;
            case 'textarea':
                ?>
<tr>
					<th scope="row"><?php 
                if ($value['tip']) {
                    ?>
<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a><?php 
                }
                ?>
<label for="<?php 
                echo esc_attr($value['id']);
                ?>
"><?php 
                echo $value['name'];
                ?>
</label></th>
					<td>
						<textarea <?php 
                if (isset($value['args'])) {
                    echo $value['args'] . ' ';
                }
                ?>
								name="<?php 
                echo esc_attr($value['id']);
                ?>
"
								id="<?php 
                echo esc_attr($value['id']);
                ?>
"
								class="large-text <?php 
                if (!empty($value['class'])) {
                    echo esc_attr($value['class']);
                }
                ?>
"
								style="<?php 
                echo esc_attr($value['css']);
                ?>
"
								placeholder="<?php 
                if (!empty($value['placeholder'])) {
                    echo esc_attr($value['placeholder']);
                }
                ?>
"
						><?php 
                echo esc_textarea(get_option($value['id']) ? stripslashes(get_option($value['id'])) : $value['std']);
                ?>
</textarea>
						<br /><small><?php 
                echo $value['desc'];
                ?>
</small>
					</td>
				</tr><?php 
                break;
            case 'tabend':
                ?>
</table></div><?php 
                $counter = $counter + 1;
                break;
            case 'single_select_page':
                $args = array('name' => $value['id'], 'id' => $value['id'] . '" style="width: 200px;', 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'selected' => (int) get_option($value['id']));
                if (!empty($value['args'])) {
                    $args = wp_parse_args($value['args'], $args);
                }
                ?>
<tr class="single_select_page">
				<th scope="row"><?php 
                if ($value['tip']) {
                    ?>
<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a><?php 
                }
                ?>
<label for="<?php 
                echo esc_attr($value['id']);
                ?>
"><?php 
                echo $value['name'];
                ?>
</label></th>
				<td>
					<?php 
                wp_dropdown_pages($args);
                ?>
					<br /><small><?php 
                echo $value['desc'];
                ?>
</small>
				</td>
			</tr><?php 
                break;
            case 'single_select_country':
                $countries = fflcommerce_countries::$countries;
                $country_setting = (string) get_option($value['id']);
                if (strstr($country_setting, ':')) {
                    $country = current(explode(':', $country_setting));
                    $state = end(explode(':', $country_setting));
                } else {
                    $country = $country_setting;
                    $state = '*';
                }
                ?>
<tr class="multi_select_countries">
					<th scope="row"><?php 
                if ($value['tip']) {
                    ?>
<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a><?php 
                }
                ?>
<label for="<?php 
                echo esc_attr($value['id']);
                ?>
"><?php 
                echo $value['name'];
                ?>
</label></th>
					<td>
						<select id="<?php 
                echo esc_attr($value['id']);
                ?>
" name="<?php 
                echo esc_attr($value['id']);
                ?>
" title="Country" style="width: 150px;">
						<?php 
                $show_all = $value['id'] != 'fflcommerce_default_country';
                echo fflcommerce_countries::country_dropdown_options($country, $state, false, $show_all);
                ?>
						</select>
					</td>
				</tr><?php 
                if (!$show_all && fflcommerce_countries::country_has_states($country) && $state == '*') {
                    fflcommerce_countries::base_country_notice();
                }
                break;
            case 'multi_select_countries':
                $countries = fflcommerce_countries::$countries;
                asort($countries);
                $selections = (array) get_option($value['id']);
                ?>
<tr class="multi_select_countries">
					<th scope="row"><?php 
                if ($value['tip']) {
                    ?>
<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a><?php 
                }
                ?>
<label><?php 
                echo $value['name'];
                ?>
</label></th>
					<td>
						<div class="multi_select_countries">
							<ul><?php 
                if ($countries) {
                    foreach ($countries as $key => $val) {
                        ?>
<li><label>
								<input type="checkbox"
									   name="<?php 
                        echo esc_attr($value['id']) . '[]';
                        ?>
"
									   value="<?php 
                        echo esc_attr($key);
                        ?>
"
									   <?php 
                        if (in_array($key, $selections)) {
                            ?>
									   checked="checked"
									   <?php 
                        }
                        ?>
								/>
								<?php 
                        echo $val;
                        ?>
								</label></li><?php 
                    }
                }
                ?>
</ul>
						</div>
					</td>
				</tr><?php 
                break;
            case 'coupons':
                _deprecated_argument('fflcommerce_admin_option_display', '1.3', 'The coupons type has no alternative. Use the new custom post Coupons Menu item under FFL Commerce.');
                $coupons = new fflcommerce_coupons();
                $coupon_codes = $coupons->get_coupons();
                ?>
		<style>
table{max-width:100%;background-color:transparent;border-collapse:collapse;border-spacing:0;}
.table{width:100%;margin-bottom:18px;}
.table th,.table td{padding:8px;line-height:18px;text-align:left;vertical-align:top;border-top:1px solid #dddddd;}
.table thead th{vertical-align:bottom;}
.table caption+thead tr:first-child th,.table caption+thead tr:first-child td,.table colgroup+thead tr:first-child th,.table colgroup+thead tr:first-child td,.table thead:first-child tr:first-child th,.table thead:first-child tr:first-child td{border-top:0;}
.table tbody+tbody{border-top:2px solid #dddddd;}
.table-condensed th,.table-condensed td{padding:4px 5px;}
.coupon-table th,.coupon-table td{padding:8px;line-height:18px;text-align:left;vertical-align:top;border-top:0px;}
</style>
			<tr><td><a href="#" class="add button" id="add_coupon"><?php 
                _e('+ Add Coupon', 'fflcommerce');
                ?>
</a></td></tr>

			<table class="coupons table">
				<thead>
					<tr>
						<th>Coupon</th>
						<th>Type</th>
						<th>Amount</th>
						<th>Usage</th>
						<th>Controls</th>
					</tr>
				</thead>
				<tbody>

				<?php 
                /* Payment methods. */
                $payment_methods = array();
                $available_gateways = fflcommerce_payment_gateways::get_available_payment_gateways();
                if (!empty($available_gateways)) {
                    foreach ($available_gateways as $id => $info) {
                        $payment_methods[$id] = $info->title;
                    }
                }
                /* Coupon types. */
                $discount_types = fflcommerce_coupons::get_coupon_types();
                /* Product categories. */
                $categories = get_terms('product_cat', array('hide_empty' => false));
                $coupon_cats = array();
                foreach ($categories as $category) {
                    $coupon_cats[$category->term_id] = $category->name;
                }
                $i = -1;
                if ($coupon_codes && is_array($coupon_codes) && sizeof($coupon_codes) > 0) {
                    foreach ($coupon_codes as $coupon) {
                        $i++;
                        ?>
				<tr>
				<td style="width:500px;">
				<table class="coupon-table form-table" id="coupons_table_<?php 
                        echo $i;
                        ?>
">
				<?php 
                        echo $coupon['code'];
                        ?>

				<tbody class="couponDisplay" id="coupons_rows_<?php 
                        echo $i;
                        ?>
">
				<?php 
                        $selected_type = '';
                        foreach ($discount_types as $type => $label) {
                            if ($coupon['type'] == $type) {
                                $selected_type = $type;
                            }
                        }
                        $options3 = array(array('name' => __('Code', 'fflcommerce'), 'tip' => __('The coupon code a customer enters on the cart or checkout page.', 'fflcommerce'), 'id' => 'coupon_code[' . esc_attr($i) . ']', 'css' => 'width:150px;', 'class' => 'coupon_code', 'type' => 'text', 'std' => esc_attr($coupon['code'])), array('name' => __('Type', 'fflcommerce'), 'tip' => __('Cart - Applies to whole cart<br/>Product - Applies to individual products only. You must specify individual products.', 'fflcommerce'), 'id' => 'coupon_type[' . esc_attr($i) . ']', 'css' => 'width:200px;', 'type' => 'select', 'std' => $selected_type, 'options' => $discount_types), array('name' => __('Amount', 'fflcommerce'), 'tip' => __('Amount this coupon is worth. If it is a percentange, just include the number without the percentage sign.', 'fflcommerce'), 'id' => 'coupon_amount[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => esc_attr($coupon['amount'])), array('name' => __('Usage limit', 'fflcommerce'), 'desc' => __(sprintf('Times used: %s', !empty($coupon['usage']) ? $coupon['usage'] : '0'), 'fflcommerce'), 'placeholder' => __('No limit', 'fflcommerce'), 'tip' => __('Control how many times this coupon may be used.', 'fflcommerce'), 'id' => 'usage_limit[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => !empty($coupon['usage_limit']) ? $coupon['usage_limit'] : ''), array('name' => __('Order subtotal', 'fflcommerce'), 'placeholder' => __('No min', 'fflcommerce'), 'desc' => __('Min', 'fflcommerce'), 'tip' => __('Set the required subtotal for this coupon to be valid on an order.', 'fflcommerce'), 'id' => 'order_total_min[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => !empty($coupon['order_total_min']) ? $coupon['order_total_min'] : '', 'group' => true), array('desc' => __('Max', 'fflcommerce'), 'placeholder' => __('No max', 'fflcommerce'), 'id' => 'order_total_max[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => !empty($coupon['order_total_max']) ? $coupon['order_total_max'] : '', 'group' => true), array('name' => __('Payment methods', 'fflcommerce'), 'tip' => __('Which payment methods are allowed for this coupon to be effective?', 'fflcommerce'), 'id' => 'coupon_pay_methods[' . esc_attr($i) . '][]', 'css' => 'width:200px;', 'class' => 'chzn-select', 'type' => 'select', 'placeholder' => 'Any method', 'multiple' => true, 'std' => !empty($coupon['coupon_pay_methods']) ? $coupon['coupon_pay_methods'] : '', 'options' => $payment_methods));
                        fflcommerce_admin_option_display($options3);
                        ?>

					<tr>
						<th scope="row">
							<a href="#" tip="<?php 
                        _e('Control which products this coupon can apply to.', 'fflcommerce');
                        ?>
" class="tips" tabindex="99"></a>
							<label for="product_ids_<?php 
                        echo esc_attr($i);
                        ?>
"><?php 
                        _e('Products', 'fflcommerce');
                        ?>
</label>
						</th>

						<td>
							<select id="product_ids_<?php 
                        echo esc_attr($i);
                        ?>
" style="width:200px;" name="product_ids[<?php 
                        echo esc_attr($i);
                        ?>
][]" style="width:100px" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php 
                        _e('Any product', 'fflcommerce');
                        ?>
">
								<?php 
                        $product_ids = $coupon['products'];
                        if ($product_ids) {
                            foreach ($product_ids as $product_id) {
                                $title = get_the_title($product_id);
                                $sku = get_post_meta($product_id, '_sku', true);
                                if (!$title) {
                                    continue;
                                }
                                if (isset($sku) && $sku) {
                                    $sku = ' (SKU: ' . $sku . ')';
                                }
                                echo '<option value="' . $product_id . '" selected="selected">' . $title . $sku . '</option>';
                            }
                        }
                        ?>
							</select> <?php 
                        _e('Include', 'fflcommerce');
                        ?>
						</td>
					  </tr>

					<tr>
						<th scope="row"></th>
						<td style="padding-top:0px;">
							<select id="exclude_product_ids_<?php 
                        echo esc_attr($i);
                        ?>
" style="width:200px;" name="exclude_product_ids[<?php 
                        echo esc_attr($i);
                        ?>
][]" style="width:100px" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php 
                        _e('Any product', 'fflcommerce');
                        ?>
">
								<?php 
                        if (!empty($coupon['exclude_products'])) {
                            foreach ($coupon['exclude_products'] as $product_id) {
                                $title = get_the_title($product_id);
                                $sku = get_post_meta($product_id, '_sku', true);
                                if (!$title) {
                                    continue;
                                }
                                if (isset($sku) && $sku) {
                                    $sku = ' (SKU: ' . $sku . ')';
                                }
                                echo '<option value="' . $product_id . '" selected="selected">' . $title . $sku . '</option>';
                            }
                        }
                        ?>
							</select> <?php 
                        _e('Exclude', 'fflcommerce');
                        ?>
						</td>
					  </tr>

					<?php 
                        $options2 = array(array('name' => __('Categories', 'fflcommerce'), 'desc' => __('Include', 'fflcommerce'), 'tip' => __('Control which categories this coupon can apply to.', 'fflcommerce'), 'id' => 'coupon_category[' . esc_attr($i) . '][]', 'type' => 'select', 'multiple' => true, 'std' => !empty($coupon['coupon_category']) ? $coupon['coupon_category'] : '', 'options' => $coupon_cats, 'class' => 'chzn-select', 'css' => 'width:200px;', 'placeholder' => 'Any category', 'group' => true), array('desc' => __('Exclude', 'fflcommerce'), 'id' => 'exclude_categories[' . esc_attr($i) . '][]', 'type' => 'select', 'multiple' => true, 'std' => !empty($coupon['exclude_categories']) ? $coupon['exclude_categories'] : '', 'options' => $coupon_cats, 'class' => 'chzn-select', 'css' => 'width:200px;', 'placeholder' => 'Any category', 'group' => true), array('name' => __('Dates allowed', 'fflcommerce'), 'desc' => __('From', 'fflcommerce'), 'placeholder' => __('Any date', 'fflcommerce'), 'tip' => __('Choose between which dates this coupon is enabled.', 'fflcommerce'), 'id' => 'coupon_date_from[' . esc_attr($i) . ']', 'css' => 'width:150px;', 'type' => 'text', 'class' => 'date-pick', 'std' => !empty($coupon['date_from']) ? date('Y-m-d', $coupon['date_from']) : '', 'group' => true), array('desc' => __('To', 'fflcommerce'), 'placeholder' => __('Any date', 'fflcommerce'), 'id' => 'coupon_date_to[' . esc_attr($i) . ']', 'css' => 'width:150px;', 'type' => 'text', 'class' => 'date-pick', 'std' => !empty($coupon['date_to']) ? date('Y-m-d', $coupon['date_to']) : '', 'group' => true), array('name' => __('Misc. settings', 'fflcommerce'), 'desc' => 'Prevent other coupons', 'tip' => __('Prevent other coupons from being used while this one is applied to a cart.', 'fflcommerce'), 'id' => 'individual[' . esc_attr($i) . ']', 'type' => 'checkbox', 'std' => isset($coupon['individual_use']) && $coupon['individual_use'] == 'yes' ? 'yes' : 'no'), array('desc' => 'Free shipping', 'tip' => __('Show the Free Shipping method on checkout with this enabled.', 'fflcommerce'), 'id' => 'coupon_free_shipping[' . esc_attr($i) . ']', 'type' => 'checkbox', 'std' => isset($coupon['coupon_free_shipping']) && $coupon['coupon_free_shipping'] == 'yes' ? 'yes' : 'no'));
                        fflcommerce_admin_option_display($options2);
                        ?>
					</tbody>
					</table>
					<script type="text/javascript">
						/* <![CDATA[ */
						jQuery(function() {
							jQuery("select#product_ids_<?php 
                        echo esc_attr($i);
                        ?>
").ajaxChosen({
								method: 	'GET',
								url: 		'<?php 
                        echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
                        ?>
',
								dataType: 	'json',
								afterTypeDelay: 100,
								data:		{
									action: 		'fflcommerce_json_search_products_and_variations',
									security: 		'<?php 
                        echo wp_create_nonce("search-products");
                        ?>
'
								}
							}, function (data) {

								var terms = {};

								jQuery.each(data, function (i, val) {
									terms[i] = val;
								});

								return terms;
							});
							jQuery("select#exclude_product_ids_<?php 
                        echo esc_attr($i);
                        ?>
").ajaxChosen({
								method: 	'GET',
								url: 		'<?php 
                        echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
                        ?>
',
								dataType: 	'json',
								afterTypeDelay: 100,
								data:		{
									action: 		'fflcommerce_json_search_products_and_variations',
									security: 		'<?php 
                        echo wp_create_nonce("search-products");
                        ?>
'
								}
							}, function (data) {

								var terms = {};

								jQuery.each(data, function (i, val) {
									terms[i] = val;
								});

								return terms;
							});
							jQuery('.date-pick').datepicker( {dateFormat: 'yy-mm-dd', gotoCurrent: true} );
						});
						/* ]]> */
					</script>
				</td>
				<td><?php 
                        echo $discount_types[$selected_type];
                        ?>
</td>
				<td><?php 
                        echo !empty($coupon['amount']) ? $coupon['amount'] : '';
                        ?>
</td>
				<td><?php 
                        echo !empty($coupon['usage']) ? $coupon['usage'] : '0';
                        ?>
</td>
				<td>
					<a class="toggleCoupon" href="#coupons_rows_<?php 
                        echo $i;
                        ?>
"><?php 
                        _e('Show', 'fflcommerce');
                        ?>
</a> /
					<a href="#" id="remove_coupon_<?php 
                        echo esc_attr($i);
                        ?>
" class="remove_coupon" title="<?php 
                        _e('Delete this Coupon', 'fflcommerce');
                        ?>
"><?php 
                        _e('Delete', 'fflcommerce');
                        ?>
</a>
				</td>
				</tr>
					<?php 
                    }
                }
                ?>
			<script type="text/javascript">

			jQuery('.couponDisplay').hide();

			/* <![CDATA[ */
			jQuery(function() {
				function toggle_coupons() {
					jQuery('a.toggleCoupon').click(function(e) {
						e.preventDefault();
						jQuery(this).text(jQuery(this).text() == '<?php 
                _e('Show', 'fflcommerce');
                ?>
' ? '<?php 
                _e('Hide', 'fflcommerce');
                ?>
' : '<?php 
                _e('Show', 'fflcommerce');
                ?>
');

						var id = jQuery(this).attr('href').substr(1);
						jQuery('#' + id).toggle('slow');
					});
				}

				toggle_coupons();

				jQuery('#add_coupon').live('click', function(e){
					e.preventDefault();
					var size = jQuery('.couponDisplay').size();
					var new_coupon = '\
					<table class="coupon-table form-table" id="coupons_table_' + size + '">\
					<tbody class="couponDisplay" id="coupons_rows_[' + size + ']">\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('The coupon code a customer enters on the cart or checkout page.', 'fflcommerce');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="coupon_code[' + size + ']"><?php 
                _e('Code', 'fflcommerce');
                ?>
</label>\
							</th>\
							<td>\
								<input name="coupon_code[' + size + ']" id="coupon_code[' + size + ']" type="text" class="regular-text coupon_code"\
								style="width:150px;" placeholder="" value="" />\
								<br />\
								<small></small>\
							</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Cart - Applies to whole cart<br/>Product - Applies to individual products only. You must specify individual products.', 'fflcommerce');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="coupon_type[' + size + ']"><?php 
                _e('Type', 'fflcommerce');
                ?>
</label>\
							</th>\
							<td>\
								<select name="coupon_type[' + size + ']" id="coupon_type[' + size + ']" style="width:150px;">\
									<option value="fixed_cart"><?php 
                _e('Cart Discount', 'fflcommerce');
                ?>
</option>\
									<option value="percent"><?php 
                _e('Cart % Discount', 'fflcommerce');
                ?>
</option>\
									<option value="fixed_product"><?php 
                _e('Product Discount', 'fflcommerce');
                ?>
</option>\
									<option value="percent_product"><?php 
                _e('Product % Discount', 'fflcommerce');
                ?>
</option>\
									</select>\
								<br />\
								<small></small>\
							</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Amount this coupon is worth. If it is a percentange, just include the number without the percentage sign.', 'fflcommerce');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="coupon_amount[' + size + ']"><?php 
                _e('Amount', 'fflcommerce');
                ?>
</label>\
							</th>\
							<td>\
								<input name="coupon_amount[' + size + ']" id="coupon_amount[' + size + ']" type="number" min="0"\
								max="" class="regular-text " style="width:60px;" value=""\
								/>\
								<br />\
								<small></small>\
							</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Control how many times this coupon may be used.', 'fflcommerce');
                ?>
" class="tips"\
								tabindex="99"></a>\
								<label for="usage_limit[' + size + ']"><?php 
                _e('Usage limit', 'fflcommerce');
                ?>
</label>\
							</th>\
							<td>\
								<input name="usage_limit[' + size + ']" id="usage_limit[' + size + ']" type="number" min="0"\
								max="" class="regular-text " style="width:60px;" placeholder="<?php 
                _e('No limit', 'fflcommerce');
                ?>
"\
								value="" />\
							</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Set the required subtotal for this coupon to be valid on an order.', 'fflcommerce');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="order_total_min[' + size + ']"><?php 
                _e('Order subtotal', 'fflcommerce');
                ?>
</label>\
							</th>\
							<td>\
								<input name="order_total_min[' + size + ']" id="order_total_min[' + size + ']" type="number"\
								min="0" max="" class="regular-text " style="width:60px;" placeholder="<?php 
                _e('No min', 'fflcommerce');
                ?>
"\
								value="" /><?php 
                _e('Min', 'fflcommerce');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row" style="padding-top:0px;"></th>\
							<td style="padding-top:0px;">\
								<input name="order_total_max[' + size + ']" id="order_total_max[' + size + ']" type="number"\
								min="0" max="" class="regular-text " style="width:60px;" placeholder="<?php 
                _e('No max', 'fflcommerce');
                ?>
"\
								value="" /><?php 
                _e('Max', 'fflcommerce');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Which payment methods are allowed for this coupon to be effective?', 'fflcommerce');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="coupon_pay_methods[' + size + '][]"><?php 
                _e('Payment methods', 'fflcommerce');
                ?>
</label>\
							</th>\
							<td>\
								<select name="coupon_pay_methods[' + size + '][]" id="coupon_pay_methods[' + size + '][]" style="width:200px;"\
								class="chzn-select" multiple="multiple">\
									<?php 
                foreach ($payment_methods as $id => $label) {
                    echo '<option value="' . $id . '">' . $label . '</option>';
                }
                ?>
\
								</select>\
								<br />\
								<small></small>\
							</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Control which products this coupon can apply to.', 'fflcommerce');
                ?>
" class="tips"\
								tabindex="99"></a>\
								<label for="product_ids_' + size + '"><?php 
                _e('Products', 'fflcommerce');
                ?>
</label>\
							</th>\
							<td>\
								<select id="product_ids_' + size + '" style="width:200px;" name="product_ids[' + size + '][]"\
								style="width:100px" class="ajax_chosen_select_products_and_variations"\
								multiple="multiple" data-placeholder="<?php 
                _e('Any product', 'fflcommerce');
                ?>
"></select><?php 
                _e('Include', 'fflcommerce');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row"></th>\
							<td style="padding-top:0px;">\
								<select id="exclude_product_ids_' + size + '" style="width:200px;" name="exclude_product_ids[' + size + '][]"\
								style="width:100px" class="ajax_chosen_select_products_and_variations"\
								multiple="multiple" data-placeholder="<?php 
                _e('Any product', 'fflcommerce');
                ?>
"></select><?php 
                _e('Exclude', 'fflcommerce');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Control which categories this coupon can apply to.', 'fflcommerce');
                ?>
" class="tips"\
								tabindex="99"></a>\
								<label for="coupon_category[' + size + '][]"><?php 
                _e('Categories', 'fflcommerce');
                ?>
</label>\
							</th>\
							<td>\
								<select name="coupon_category[' + size + '][]" id="coupon_category_' + size + '" style="width:200px;"\
								class="chzn-select" multiple="multiple">\
								   <?php 
                $categories = get_terms('product_cat', array('hide_empty' => false));
                foreach ($categories as $category) {
                    echo '<option value="' . $category->term_id . '">' . $category->name . '</option>';
                }
                ?>
\
								</select><?php 
                _e('Include', 'fflcommerce');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<label for="exclude_categories[' + size + '][]"></label>\
							</th>\
							<td>\
								<select name="exclude_categories[' + size + '][]" id="exclude_categories_' + size + '" style="width:200px;"\
								class="chzn-select" multiple="multiple">\
									<?php 
                $categories = get_terms('product_cat', array('hide_empty' => false));
                foreach ($categories as $category) {
                    echo '<option value="' . $category->term_id . '">' . $category->name . '</option>';
                }
                ?>
\
								</select><?php 
                _e('Exclude', 'fflcommerce');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Choose between which dates this coupon is enabled.', 'fflcommerce');
                ?>
" class="tips"\
								tabindex="99"></a>\
								<label for="coupon_date_from[' + size + ']"><?php 
                _e('Dates allowed', 'fflcommerce');
                ?>
</label>\
							</th>\
							<td>\
								<input name="coupon_date_from[' + size + ']" id="coupon_date_from[' + size + ']" type="text"\
								class="regular-text date-pick" style="width:150px;" placeholder="<?php 
                _e('Any date', 'fflcommerce');
                ?>
"\
								value="" /><?php 
                _e('From', 'fflcommerce');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row" style="padding-top:0px;"></th>\
							<td style="padding-top:0px;">\
								<input name="coupon_date_to[' + size + ']" id="coupon_date_to[' + size + ']" type="text" class="regular-text date-pick"\
								style="width:150px;" placeholder="<?php 
                _e('Any date', 'fflcommerce');
                ?>
" value="" /><?php 
                _e('To', 'fflcommerce');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Prevent other coupons from being used while this one is applied to a cart.', 'fflcommerce');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="individual[' + size + ']"><?php 
                _e('Misc. settings', 'fflcommerce');
                ?>
</label>\
							</th>\
							<td>\
								<input id="individual[' + size + ']" type="checkbox" class="fflcommerce-input fflcommerce-checkbox "\
								style="" name="individual[' + size + ']" />\
								<label for="individual[' + size + ']"><?php 
                _e('Prevent other coupons', 'fflcommerce');
                ?>
</label>\
							</td>\
						</tr>\
						<tr>\
							<th scope="row" style="padding-top:0px;">\
								<a href="#" tip="<?php 
                _e('Show the Free Shipping method on checkout with this enabled.', 'fflcommerce');
                ?>
"\
								class="tips" tabindex="99"></a>\
							</th>\
							<td style="padding-top:0px;">\
								<input id="coupon_free_shipping[' + size + ']" type="checkbox" class="fflcommerce-input fflcommerce-checkbox "\
								style="" name="coupon_free_shipping[' + size + ']" />\
								<label for="coupon_free_shipping[' + size + ']"><?php 
                _e('Free shipping', 'fflcommerce');
                ?>
</label>\
							</td>\
						</tr>\
					</tbody>\
					</table>\
					';
					/* Add the table */
					jQuery('.coupons.table').before(new_coupon);
					jQuery('#coupons_table_' + size).hide().fadeIn('slow');

					jQuery("select#product_ids_" + size).ajaxChosen({
						method: 	'GET',
						url: 		'<?php 
                echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
                ?>
',
						dataType: 	'json',
						afterTypeDelay: 100,
						data:		{
							action: 		'fflcommerce_json_search_products_and_variations',
							security: 		'<?php 
                echo wp_create_nonce("search-products");
                ?>
'
						}
					}, function (data) {

						var terms = {};

						jQuery.each(data, function (i, val) {
							terms[i] = val;
						});

						return terms;
					});
					jQuery("select#exclude_product_ids_" + size).ajaxChosen({
						method: 	'GET',
						url: 		'<?php 
                echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
                ?>
',
						dataType: 	'json',
						afterTypeDelay: 100,
						data:		{
							action: 		'fflcommerce_json_search_products_and_variations',
							security: 		'<?php 
                echo wp_create_nonce("search-products");
                ?>
'
						}
					}, function (data) {

						var terms = {};

						jQuery.each(data, function (i, val) {
							terms[i] = val;
						});

						return terms;
					});
					jQuery('a[href="#coupons_rows_'+size+'"]').click(function(e) {
						e.preventDefault();
						jQuery('#coupons_rows_'+size).toggle('slow', function() {
							// Stuff later?
						});
					});
					jQuery(".chzn-select").chosen();
					jQuery(".tips").tooltip();
					jQuery('.date-pick').datepicker( {dateFormat: 'yy-mm-dd', gotoCurrent: true} );
					return false;
				});
				jQuery('a.remove_coupon').live('click', function(){
					var answer = confirm("<?php 
                _e('Delete this coupon?', 'fflcommerce');
                ?>
")
					if (answer) {
						jQuery('input', jQuery(this).parent().parent().children()).val('');
						jQuery(this).parent().parent().fadeOut();
					}
					return false;
				});
			});
		/* ]]> */
		</script>
						<?php 
                break;
            case 'tax_rates':
                $_tax = new fflcommerce_tax();
                $tax_classes = $_tax->get_tax_classes();
                $tax_rates = get_option('fflcommerce_tax_rates');
                $applied_all_states = array();
                ?>
<tr>
					<th><?php 
                if ($value['tip']) {
                    ?>
<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a><?php 
                }
                ?>
<label><?php 
                echo $value['name'];
                ?>
</label></th>
					<td id="tax_rates">
						<div class="taxrows">
			<?php 
                $i = -1;
                if ($tax_rates && is_array($tax_rates) && sizeof($tax_rates) > 0) {
                    function array_find($needle, $haystack)
                    {
                        foreach ($haystack as $key => $val) {
                            if ($needle == array("label" => $val['label'], "compound" => $val['compound'], 'rate' => $val['rate'], 'shipping' => $val['shipping'], 'is_all_states' => $val['is_all_states'], 'class' => $val['class'])) {
                                return $key;
                            }
                        }
                        return false;
                    }
                    function array_compare($tax_rates)
                    {
                        $after = array();
                        foreach ($tax_rates as $key => $val) {
                            $first_two = array("label" => $val['label'], "compound" => $val['compound'], 'rate' => $val['rate'], 'shipping' => $val['shipping'], 'is_all_states' => $val['is_all_states'], 'class' => $val['class']);
                            $found = array_find($first_two, $after);
                            if ($found !== false) {
                                $combined = $after[$found]["state"];
                                $combined2 = $after[$found]["country"];
                                $combined = !is_array($combined) ? array($combined) : $combined;
                                $combined2 = !is_array($combined2) ? array($combined2) : $combined2;
                                $after[$found] = array_merge($first_two, array("state" => array_merge($combined, array($val['state'])), "country" => array_merge($combined2, array($val['country']))));
                            } else {
                                $after = array_merge($after, array(array_merge($first_two, array("state" => $val['state'], "country" => $val['country']))));
                            }
                        }
                        return $after;
                    }
                    $tax_rates = array_compare($tax_rates);
                    foreach ($tax_rates as $rate) {
                        if ($rate['is_all_states'] && in_array(get_all_states_key($rate), $applied_all_states)) {
                            continue;
                        }
                        $i++;
                        // increment counter after check for all states having been applied
                        echo '<p class="taxrow">
					<select name="tax_classes[' . esc_attr($i) . ']" title="Tax Classes">
						<option value="*">' . __('Standard Rate', 'fflcommerce') . '</option>';
                        if ($tax_classes) {
                            foreach ($tax_classes as $class) {
                                echo '<option value="' . sanitize_title($class) . '"';
                                if ($rate['class'] == sanitize_title($class)) {
                                    echo 'selected="selected"';
                                }
                                echo '>' . $class . '</option>';
                            }
                        }
                        echo '</select>

					<input type="text"
						   class="text" value="' . esc_attr($rate['label']) . '"
						   name="tax_label[' . esc_attr($i) . ']"
						   title="' . __('Online Label', 'fflcommerce') . '"
						   placeholder="' . __('Online Label', 'fflcommerce') . '"
						   maxlength="15" />';
                        echo '<select name="tax_country[' . esc_attr($i) . '][]" title="Country" multiple="multiple" style="width:250px;">';
                        if ($rate['is_all_states']) {
                            if (is_array($applied_all_states) && !in_array(get_all_states_key($rate), $applied_all_states)) {
                                $applied_all_states[] = get_all_states_key($rate);
                                fflcommerce_countries::country_dropdown_options($rate['country'], '*');
                                //all-states
                            } else {
                                continue;
                            }
                        } else {
                            fflcommerce_countries::country_dropdown_options($rate['country'], $rate['state']);
                        }
                        echo '</select>

					<input type="text"
						   class="text"
						   value="' . esc_attr($rate['rate']) . '"
						   name="tax_rate[' . esc_attr($i) . ']"
						   title="' . __('Rate', 'fflcommerce') . '"
						   placeholder="' . __('Rate', 'fflcommerce') . '"
						   maxlength="8" />%

					<label><input type="checkbox" name="tax_shipping[' . esc_attr($i) . ']" ';
                        if (isset($rate['shipping']) && $rate['shipping'] == 'yes') {
                            echo 'checked="checked"';
                        }
                        echo ' /> ' . __('Apply to shipping', 'fflcommerce') . '</label>

					<label><input type="checkbox" name="tax_compound[' . esc_attr($i) . ']" ';
                        if (isset($rate['compound']) && $rate['compound'] == 'yes') {
                            echo 'checked="checked"';
                        }
                        echo ' /> ' . __('Compound', 'fflcommerce') . '</label>

					<a href="#" class="remove button">&times;</a></p>';
                    }
                }
                ?>
						</div>
						<p><a href="#" class="add button"><?php 
                _e('+ Add Tax Rule', 'fflcommerce');
                ?>
</a></p>
					</td>
				</tr>
				<script type="text/javascript">
					/* <![CDATA[ */
					jQuery(function() {
						jQuery('#tax_rates a.add').live('click', function(){
							var size = jQuery('.taxrows .taxrow').size();

							// Add the row
							jQuery('<p class="taxrow"> \
								<select name="tax_classes[' + size + ']" title="Tax Classes"> \
									<option value="*"><?php 
                _e('Standard Rate', 'fflcommerce');
                ?>
</option><?php 
                $tax_classes = $_tax->get_tax_classes();
                if ($tax_classes) {
                    foreach ($tax_classes as $class) {
                        echo '<option value="' . sanitize_title($class) . '">' . $class . '</option>';
                    }
                }
                ?>
</select><input type="text" class="text" name="tax_label[' + size + ']" title="<?php 
                _e('Online Label', 'fflcommerce');
                ?>
" placeholder="<?php 
                _e('Online Label', 'fflcommerce');
                ?>
" maxlength="15" />\
									</select><select name="tax_country[' + size + '][]" title="Country" multiple="multiple"><?php 
                fflcommerce_countries::country_dropdown_options('', '', true);
                ?>
</select><input type="text" class="text" name="tax_rate[' + size + ']" title="<?php 
                _e('Rate', 'fflcommerce');
                ?>
" placeholder="<?php 
                _e('Rate', 'fflcommerce');
                ?>
" maxlength="8" />%\
									<label><input type="checkbox" name="tax_shipping[' + size + ']" /> <?php 
                _e('Apply to shipping', 'fflcommerce');
                ?>
</label>\
									<label><input type="checkbox" name="tax_compound[' + size + ']" /> <?php 
                _e('Compound', 'fflcommerce');
                ?>
</label><a href="#" class="remove button">&times;</a>\
							</p>').appendTo('#tax_rates div.taxrows');
												return false;
											});
											jQuery('#tax_rates a.remove').live('click', function(){
												var answer = confirm("<?php 
                _e('Delete this rule?', 'fflcommerce');
                ?>
");
												if (answer) {
													jQuery('input', jQuery(this).parent()).val('');
													jQuery(this).parent().hide();
												}
												return false;
											});
										});
										/* ]]> */
				</script>
			<?php 
                break;
            case "shipping_options":
                foreach (fflcommerce_shipping::get_all_methods() as $method) {
                    $method->admin_options();
                }
                break;
            case "gateway_options":
                foreach (fflcommerce_payment_gateways::payment_gateways() as $gateway) {
                    $gateway->admin_options();
                }
                break;
        }
    }
}
Exemplo n.º 10
0
/**
 * Coupon data meta box
 *
 * Displays the meta box
 */
function fflcommerce_coupon_data_box($post)
{
    global $fflcommerce;
    wp_nonce_field('fflcommerce_save_data', 'fflcommerce_meta_nonce');
    $coupon_code = '';
    $coupon_code .= "<p class='form-field'>";
    $coupon_code .= "<label>" . __('Coupon Code', 'fflcommerce') . "</label>";
    $coupon_code .= "<span><strong>" . $post->post_name . "</strong></span>";
    $coupon_code .= '<span class="description">' . __('Will not appear until coupon is saved.  This is the front end code for use on the Cart.', 'fflcommerce') . '</span>';
    $coupon_code .= "</p>";
    // disable the permalink slug display
    ?>
		<style type="text/css">#edit-slug-box { display:none }</style>

		<div id="coupon_options" class="panel fflcommerce_options_panel">

			<div class="options_group">

			<?php 
    // The coupon code from the title after 'sanitize_title'
    echo $coupon_code;
    // Coupon Types
    $args = array('id' => 'type', 'label' => __('Coupon Type', 'fflcommerce'), 'options' => JS_Coupons::get_coupon_types());
    echo FFLCommerce_Forms::select($args);
    // Amount
    $args = array('id' => 'amount', 'label' => __('Coupon Amount', 'fflcommerce'), 'type' => 'number', 'min' => 0, 'desc' => __('Enter an amount e.g. 9.99.', 'fflcommerce'), 'tip' => __('Amount this coupon is worth. If it is a percentange, just include the number without the percentage sign.', 'fflcommerce'), 'placeholder' => '0.00');
    echo FFLCommerce_Forms::input($args);
    // Date From
    $coupon_date_from = get_post_meta($post->ID, 'date_from', true);
    $args = array('id' => 'date_from', 'label' => __('Date From', 'fflcommerce'), 'desc' => __('yyyy-mm-dd', 'fflcommerce'), 'tip' => __('Choose between which dates this coupon is enabled.  Leave empty for any date.', 'fflcommerce'), 'class' => 'short date-pick', 'placeholder' => __('Any date', 'fflcommerce'), 'value' => $coupon_date_from != '' ? date('Y-m-d', $coupon_date_from) : '');
    echo FFLCommerce_Forms::input($args);
    // Date To
    $coupon_date_to = get_post_meta($post->ID, 'date_to', true);
    $args = array('id' => 'date_to', 'label' => __('Date To', 'fflcommerce'), 'desc' => __('yyyy-mm-dd', 'fflcommerce'), 'tip' => __('Choose between which dates this coupon is enabled.  Leave empty for any date.', 'fflcommerce'), 'class' => 'short date-pick', 'placeholder' => __('Any date', 'fflcommerce'), 'value' => $coupon_date_to != '' ? date('Y-m-d', $coupon_date_to) : '');
    echo FFLCommerce_Forms::input($args);
    // Usage limit
    $usage = get_post_meta($post->ID, 'usage', true);
    $args = array('id' => 'usage_limit', 'label' => __('Usage Limit', 'fflcommerce'), 'type' => 'number', 'desc' => sprintf(__('Times used: %s', 'fflcommerce'), !empty($usage) ? $usage : '0'), 'tip' => __('Control how many times this coupon may be used.', 'fflcommerce'), 'placeholder' => '0');
    echo FFLCommerce_Forms::input($args);
    // Individual use
    $args = array('id' => 'individual_use', 'label' => __('Individual Use', 'fflcommerce'), 'desc' => __('Prevent other coupons from being used while this one is applied to the Cart.', 'fflcommerce'), 'value' => false);
    echo FFLCommerce_Forms::checkbox($args);
    // Free shipping
    $args = array('id' => 'free_shipping', 'label' => __('Free shipping', 'fflcommerce'), 'desc' => __('Show the Free Shipping method on the Checkout with this enabled.', 'fflcommerce'), 'value' => false);
    echo FFLCommerce_Forms::checkbox($args);
    ?>
			</div><div class="options_group">
		<?php 
    // Order total minimum
    $args = array('id' => 'order_total_min', 'label' => __('Order total min', 'fflcommerce'), 'type' => 'number', 'desc' => __('Set the required minimum subtotal for this coupon to be valid on an order.', 'fflcommerce'), 'placeholder' => __('No min', 'fflcommerce'));
    echo FFLCommerce_Forms::input($args);
    // Order total maximum
    $args = array('id' => 'order_total_max', 'label' => __('Order total max', 'fflcommerce'), 'type' => 'number', 'desc' => __('Set the required maximum subtotal for this coupon to be valid on an order.', 'fflcommerce'), 'placeholder' => __('No max', 'fflcommerce'));
    echo FFLCommerce_Forms::input($args);
    ?>
			</div><div class="options_group">
		<?php 
    // Include product ID's
    $selected = get_post_meta($post->ID, 'include_products', true);
    $selected = implode(',', (array) $selected);
    $args = array('id' => 'include_products', 'type' => 'hidden', 'class' => 'long', 'label' => __('Include Products', 'fflcommerce'), 'desc' => __('Control which products this coupon can apply to.', 'fflcommerce'), 'value' => $selected);
    echo FFLCommerce_Forms::input($args);
    // Exclude product ID's
    $selected = get_post_meta($post->ID, 'exclude_products', true);
    $selected = implode(',', (array) $selected);
    $args = array('id' => 'exclude_products', 'type' => 'hidden', 'class' => 'long', 'label' => __('Exclude Products', 'fflcommerce'), 'desc' => __('Control which products this coupon cannot be applied to.', 'fflcommerce'), 'value' => $selected);
    echo FFLCommerce_Forms::input($args);
    ?>
			</div><div class="options_group">
		<?php 
    // Include Categories
    $categories = get_terms('product_cat', array('hide_empty' => false));
    $coupon_cats = array();
    foreach ($categories as $category) {
        $coupon_cats[$category->term_id] = $category->name;
    }
    $args = array('id' => 'include_categories', 'label' => __('Include Categories', 'fflcommerce'), 'desc' => __('Control which product categories this coupon can apply to.', 'fflcommerce'), 'multiple' => true, 'placeholder' => __('Any category', 'fflcommerce'), 'options' => $coupon_cats);
    echo FFLCommerce_Forms::select($args);
    // Exclude Categories
    $args = array('id' => 'exclude_categories', 'label' => __('Exclude Categories', 'fflcommerce'), 'desc' => __('Control which product categories this coupon cannot be applied to.', 'fflcommerce'), 'multiple' => true, 'placeholder' => __('No exclusions', 'fflcommerce'), 'options' => $coupon_cats);
    echo FFLCommerce_Forms::select($args);
    ?>
			</div><div class="options_group">
		<?php 
    // Payment methods
    $payment_methods = array();
    $available_gateways = fflcommerce_payment_gateways::get_available_payment_gateways();
    if (!empty($available_gateways)) {
        foreach ($available_gateways as $id => $info) {
            $payment_methods[$id] = $info->title;
        }
    }
    $args = array('id' => 'pay_methods', 'label' => __('Payment Methods', 'fflcommerce'), 'desc' => __('Control which payment methods are allowed for this coupon to be effective.', 'fflcommerce'), 'multiple' => true, 'placeholder' => __('Any method', 'fflcommerce'), 'options' => $payment_methods);
    echo FFLCommerce_Forms::select($args);
    // javascript for product includes and excludes -- need to move this
    ?>
			<script type="text/javascript">
			/*<![CDATA[*/
				jQuery(document).ready(function($) {
					$('#date_from').datepicker( {dateFormat: 'yy-mm-dd', gotoCurrent: true} );
					$('#date_to').datepicker( {dateFormat: 'yy-mm-dd', gotoCurrent: true} );

					// allow searching of products to use on a coupon
					$("#include_products").select2({
						minimumInputLength: 3,
						multiple: true,
						closeOnSelect: true,
						placeholder: "<?php 
    _e('Any product', 'fflcommerce');
    ?>
",
						ajax: {
							url: "<?php 
    echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
    ?>
",
							dataType: 'json',
							quietMillis: 100,
							data: function(term, page) {
								return {
									term:       term,
									action:     'fflcommerce_json_search_products_and_variations',
									security:   '<?php 
    echo wp_create_nonce("search-products");
    ?>
'
								};
							},
							results: function( data, page ) {
								return { results: data };
							}
						},
						initSelection: function( element, callback ) {
							var stuff = {
								action:     'fflcommerce_json_search_products_and_variations',
								security:   '<?php 
    echo wp_create_nonce("search-products");
    ?>
',
								term:       element.val()
							};
							var data = [];
							$.ajax({
								type: 		'GET',
								url:        "<?php 
    echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
    ?>
",
								dataType: 	"json",
								data: 		stuff,
								success: 	function( result ) {
									callback( result );
								}
							});
						}
					});

					// allow searching of products to exclude on a coupon
					$("#exclude_products").select2({
						minimumInputLength: 3,
						multiple: true,
						closeOnSelect: true,
						placeholder: "<?php 
    _e('No exclusions', 'fflcommerce');
    ?>
",
						ajax: {
							url: "<?php 
    echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
    ?>
",
							dataType: 'json',
							quietMillis: 100,
							data: function(term, page) {
								return {
									term:       term,
									action:     'fflcommerce_json_search_products_and_variations',
									security:   '<?php 
    echo wp_create_nonce("search-products");
    ?>
'
								};
							},
							results: function( data, page ) {
								return { results: data };
							}
						},
						initSelection: function( element, callback ) {
							var stuff = {
								action:     'fflcommerce_json_search_products_and_variations',
								security:   '<?php 
    echo wp_create_nonce("search-products");
    ?>
',
								term:       element.val()
							};
							$.ajax({
								type: 		'GET',
								url:        "<?php 
    echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
    ?>
",
								dataType: 	"json",
								data: 		stuff,
								success: 	function( result ) {
									callback( result );
								}
							});
						}
					});
				});
			/*]]>*/
			</script>
		</div></div>
	<?php 
}