Esempio n. 1
0
function fflcommerce_product_tag($attributes)
{
    global $paged;
    $fflcommerce_options = FFLCommerce_Base::get_options();
    $attributes = shortcode_atts(array('tag' => '', 'per_page' => $fflcommerce_options->get('fflcommerce_catalog_per_page'), 'columns' => $fflcommerce_options->get('fflcommerce_catalog_columns'), 'orderby' => $fflcommerce_options->get('fflcommerce_catalog_sort_orderby'), 'order' => $fflcommerce_options->get('fflcommerce_catalog_sort_direction'), 'pagination' => false, 'tax_operator' => 'IN'), $attributes);
    if (isset($_REQUEST['tag'])) {
        $attributes['tag'] = $_REQUEST['tag'];
    }
    /** Operator validation. */
    if (!in_array($attributes['tax_operator'], array('IN', 'NOT IN', 'AND'))) {
        $tax_operator = 'IN';
    }
    /** Multiple category values. */
    if (!empty($slug)) {
        $slug = explode(',', esc_attr($slug));
        $slug = array_map('trim', $slug);
    }
    $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $attributes['per_page'], 'orderby' => $attributes['orderby'], 'order' => $attributes['order'], 'paged' => $paged, 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')), 'tax_query' => array(array('taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $attributes['tag'], 'operator' => $attributes['tax_operator'])));
    query_posts($args);
    ob_start();
    fflcommerce_get_template_part('loop', 'shop');
    if ($attributes['pagination']) {
        do_action('fflcommerce_pagination');
    }
    wp_reset_query();
    return ob_get_clean();
}
 public function calculate_shipping()
 {
     /** @var \fflcommerce_tax $_tax */
     $_tax = $this->get_tax();
     $this->shipping_total = 0;
     $this->shipping_tax = 0;
     if ($this->type == 'order') {
         // Shipping for whole order
         $this->shipping_total = $this->cost + $this->get_fee($this->fee, fflcommerce_cart::$cart_contents_total);
         $this->shipping_total = $this->shipping_total < 0 ? 0 : $this->shipping_total;
         if (FFLCommerce_Base::get_options()->get('fflcommerce_calc_taxes') == 'yes' && $this->tax_status == 'taxable') {
             $this->shipping_tax = $this->calculate_shipping_tax($this->shipping_total);
         }
     } else {
         if (sizeof(fflcommerce_cart::$cart_contents) > 0) {
             foreach (fflcommerce_cart::$cart_contents as $item_id => $values) {
                 /** @var fflcommerce_product $_product */
                 $_product = $values['data'];
                 if ($_product->exists() && $values['quantity'] > 0 && !$_product->is_type('downloadable')) {
                     $item_shipping_price = ($this->cost + $this->get_fee($this->fee, $_product->get_price())) * $values['quantity'];
                     $this->shipping_total = $this->shipping_total + $item_shipping_price;
                     //TODO: need to figure out how to handle per item shipping with discounts that apply to shipping as well
                     // * currently not working. Will need to fix
                     if ($_product->is_shipping_taxable() && $this->tax_status == 'taxable') {
                         $_tax->calculate_shipping_tax($item_shipping_price, $this->id, $_product->get_tax_classes());
                     }
                 }
             }
             $this->shipping_tax = $_tax->get_total_shipping_tax_amount();
         }
     }
 }
Esempio n. 3
0
function fflcommerce_product_list($attributes)
{
    $options = FFLCommerce_Base::get_options();
    $attributes = shortcode_atts(array('number' => $options->get('fflcommerce_catalog_per_page'), 'order_by' => 'date', 'order' => 'desc', 'orientation' => 'rows', 'taxonomy' => 'product_cat', 'terms' => '', 'thumbnails' => 'show', 'sku' => 'hide'), $attributes);
    $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $attributes['number'], 'orderby' => $attributes['order_by'], 'order' => $attributes['order'], 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
    if (!empty($attributes['taxonomy']) && !empty($attributes['terms'])) {
        $args['tax_query'] = array(array('taxonomy' => $attributes['taxonomy'], 'terms' => $attributes['terms'], 'field' => 'slug'));
    }
    $query = new WP_Query($args);
    remove_action('fflcommerce_before_shop_loop_item_title', 'fflcommerce_template_loop_product_thumbnail', 10);
    if ($attributes['thumbnails'] === 'show') {
        add_action('fflcommerce_before_shop_loop_item', 'fflcommerce_product_thumbnail', 10, 2);
    }
    if ($attributes['sku'] === 'show') {
        add_action('fflcommerce_after_shop_loop_item_title', 'fflcommerce_product_sku', 9, 2);
    }
    $result = fflcommerce_render_result('shortcode/product_list', array('orientation' => $attributes['orientation'], 'products' => $query->get_posts(), 'has_thumbnails' => $attributes['thumbnails'] === 'show'));
    if ($attributes['sku'] === 'show') {
        remove_action('fflcommerce_after_shop_loop_item_title', 'fflcommerce_product_sku', 9);
    }
    if ($attributes['thumbnails'] === 'show') {
        remove_action('fflcommerce_before_shop_loop_item', 'fflcommerce_product_thumbnail', 10);
    }
    add_action('fflcommerce_before_shop_loop_item_title', 'fflcommerce_template_loop_product_thumbnail', 10, 2);
    return $result;
}
Esempio n. 4
0
 /**
  * Constructor
  * Setup the widget with the available options
  * Add actions to clear the cache whenever a post is saved|deleted or a theme is switched
  */
 public function __construct()
 {
     $options = array('classname' => 'fflcommerce_cart', 'description' => __('Shopping Cart for the sidebar', 'fflcommerce'));
     // Create the widget
     parent::__construct('fflcommerce_cart', __('Jigoshop: Cart', 'fflcommerce'), $options);
     $this->options = FFLCommerce_Base::get_options();
 }
Esempio n. 5
0
 /**
  * Widget
  * Display the widget in the sidebar
  * Save output to the cache if empty
  *
  * @param  array  sidebar arguments
  * @param  array  instance
  */
 public function widget($args, $instance)
 {
     extract($args);
     // Print the widget wrapper
     echo $before_widget;
     if (is_user_logged_in()) {
         // Get current user instance
         global $current_user;
         // Print title
         $title = $instance['title_user'] ? $instance['title_user'] : __('Hey %s!', 'fflcommerce');
         if ($title) {
             echo $before_title . sprintf($title, ucwords($current_user->display_name)) . $after_title;
         }
         // Create the default set of links
         $links = apply_filters('fflcommerce_widget_logout_user_links', array(__('My Account', 'fflcommerce') => get_permalink(fflcommerce_get_page_id('myaccount')), __('Change Password', 'fflcommerce') => get_permalink(fflcommerce_get_page_id('change_password')), __('Logout', 'fflcommerce') => wp_logout_url(home_url())));
     } else {
         // Print title
         $title = $instance['title_guest'] ? $instance['title_guest'] : __('Login', 'fflcommerce');
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         do_action('fflcommerce_widget_login_before_form');
         // Get redirect URI
         $redirect_to = apply_filters('fflcommerce_widget_login_redirect', get_permalink(fflcommerce_get_page_id('myaccount')));
         $fields = array();
         // Support for other plugins which uses GET parameters
         $fields = apply_filters('fflcommerce_get_hidden_fields', $fields);
         echo "<form action='" . esc_url(wp_login_url($redirect_to)) . "' method='post' class='fflcommerce_login_widget'>";
         foreach ($fields as $key => $value) {
             echo '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
         }
         // Username
         echo "\n\t\t\t<p>\n\t\t\t\t<label for='log'>" . __('Username', 'fflcommerce') . "</label>\n\t\t\t\t<input type='text' name='log' id='log' class='input-text username' />\n\t\t\t</p>\n\t\t\t";
         // Password
         echo "\n\t\t\t<p>\n\t\t\t\t<label for='pwd'>" . __('Password', 'fflcommerce') . "</label>\n\t\t\t\t<input type='password' name='pwd' id='pwd' class='input-text password' />\n\t\t\t</p>\n\t\t\t";
         echo "\n\t\t\t<p>\n\t\t\t\t<input type='submit' name='submit' value='" . __('Login', 'fflcommerce') . "' class='input-submit' />\n\t\t\t\t<a class='forgot' href='" . esc_url(wp_lostpassword_url($redirect_to)) . "'>" . __('Forgot it?', 'fflcommerce') . "</a>\n\t\t\t</p>\n\t\t\t";
         if (FFLCommerce_Base::get_options()->get('fflcommerce_enable_signup_form') == 'yes') {
             echo '<p class="register">';
             wp_register(__('New user?', 'fflcommerce') . ' ', '');
             echo '</p>';
         }
         echo "</form>";
         do_action('fflcommerce_widget_login_after_form');
         $links = apply_filters('fflcommerce_widget_login_user_links', array());
     }
     // Loop & print out the links
     if ($links) {
         echo "\n\t\t\t<nav role='navigation'>\n\t\t\t\t<ul class='pagenav'>";
         foreach ($links as $title => $href) {
             $href = esc_url($href);
             echo "<li><a title='Go to {$title}' href='{$href}'>{$title}</a></li>";
         }
         echo "\n\t\t\t\t</ul>\n\t\t\t</nav>";
     }
     // Print closing widget wrapper
     echo $after_widget;
 }
 /**
  * Get Products matching stock criteria
  */
 public function get_items($current_page, $per_page)
 {
     global $wpdb;
     $this->max_items = 0;
     $this->items = array();
     $options = FFLCommerce_Base::get_options();
     $stock = absint(max($options->get('fflcommerce_notify_no_stock_amount'), 0));
     $query_from = apply_filters('fflcommerce_report_out_of_stock_query_from', "FROM {$wpdb->posts} as posts\n\t\t\tINNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id\n\t\t\tINNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id\n\t\t\tWHERE 1=1\n\t\t\tAND posts.post_type IN ('product', 'product_variation')\n\t\t\tAND posts.post_status = 'publish'\n\t\t\tAND ((posts.post_type = 'product' AND postmeta2.meta_key = 'manage_stock' AND postmeta2.meta_value = '1') OR (posts.post_type = 'product_variation'))\n\t\t\tAND postmeta.meta_key = 'stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}'\n\t\t");
     $this->items = $wpdb->get_results($wpdb->prepare("SELECT posts.ID as id, posts.post_parent as parent {$query_from} GROUP BY posts.ID ORDER BY posts.post_title DESC LIMIT %d, %d;", ($current_page - 1) * $per_page, $per_page));
     $this->max_items = $wpdb->get_var("SELECT COUNT( DISTINCT posts.ID ) {$query_from};");
 }
Esempio n. 7
0
 public function __construct()
 {
     parent::__construct();
     $this->id = 'cheque';
     $this->icon = '';
     $this->has_fields = false;
     $this->enabled = FFLCommerce_Base::get_options()->get('fflcommerce_cheque_enabled');
     $this->title = FFLCommerce_Base::get_options()->get('fflcommerce_cheque_title');
     $this->description = FFLCommerce_Base::get_options()->get('fflcommerce_cheque_description');
     add_action('thankyou_cheque', array(&$this, 'thankyou_page'));
 }
Esempio n. 8
0
 public function displayFileUpload()
 {
     ob_start();
     echo '<table>';
     if (\FFLCommerce_Base::get_options()->exists('fflcommerce_cart_favicon_count_url')) {
         echo '<tr><td>' . __('Actual icon:', 'fflcommerce_cart_favicon_count') . '</td><td><img src="' . \Jigoshop_Base::get_options()->get('fflcommerce_cart_favicon_count_url') . '"/></td></tr>';
     }
     echo '<tr><td>' . __('Upload new icon:', 'fflcommerce_cart_favicon_count') . '</td><td><input type="file" id="fflcommerce_cart_favicon_count_file" name="fflcommerce_cart_favicon_count_file" value="" /></td></tr>';
     echo '</table>';
     return ob_get_clean();
 }
Esempio n. 9
0
 /**
  * Process the payment and return the result
  **/
 function process_payment($order_id)
 {
     $order = new fflcommerce_order($order_id);
     $status = FFLCommerce_Base::get_options()->get('fflcommerce_cod_status', 'processing');
     $order->update_status($status, __('Waiting for cash delivery.', 'fflcommerce'));
     // Remove cart
     fflcommerce_cart::empty_cart();
     // Return thankyou redirect
     $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks'));
     return array('result' => 'success', 'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect))));
 }
function fflcommerce_save_attributes()
{
    /** @var $wpdb wpdb */
    global $wpdb;
    $options = FFLCommerce_Base::get_options();
    if (isset($_POST['add_new_attribute']) && $_POST['add_new_attribute']) {
        check_admin_referer('fflcommerce-add-attribute', '_fflcommerce_csrf');
        $attribute_label = (string) strip_tags(stripslashes($_POST['attribute_label']));
        $attribute_name = !$_POST['attribute_name'] ? sanitize_title(sanitize_user($attribute_label, $strict = true)) : sanitize_title(sanitize_user($_POST['attribute_name'], $strict = true));
        $attribute_type = (string) $_POST['attribute_type'];
        if (empty($attribute_name) && empty($attribute_label) || empty($attribute_label)) {
            print_r('<div id="message" class="error"><p>' . __('Please enter an attribute label.', 'fflcommerce') . '</p></div>');
        } elseif ($attribute_name && strlen($attribute_name) < 30 && $attribute_type && !taxonomy_exists('pa_' . sanitize_title($attribute_name))) {
            $wpdb->insert($wpdb->prefix . "fflcommerce_attribute_taxonomies", array('attribute_name' => $attribute_name, 'attribute_label' => $attribute_label, 'attribute_type' => $attribute_type), array('%s', '%s'));
            do_action('fflcommerce_attribute_admin_add_after_save', $attribute_name, $attribute_label, $attribute_type);
            $options->set('jigowatt_update_rewrite_rules', '1');
            wp_safe_redirect(get_admin_url() . 'edit.php?post_type=product&page=fflcommerce_attributes');
            exit;
        } else {
            print_r('<div id="message" class="error"><p>' . __('That attribute already exists, no additions were made.', 'fflcommerce') . '</p></div>');
        }
    } elseif (isset($_POST['save_attribute']) && $_POST['save_attribute'] && isset($_GET['edit'])) {
        $edit = absint($_GET['edit']);
        check_admin_referer('fflcommerce-edit-attribute_' . $edit, '_fflcommerce_csrf');
        if ($edit > 0) {
            $attribute_type = $_POST['attribute_type'];
            $attribute_label = (string) strip_tags(stripslashes($_POST['attribute_label']));
            $wpdb->update($wpdb->prefix . "fflcommerce_attribute_taxonomies", array('attribute_type' => $attribute_type, 'attribute_label' => $attribute_label), array('attribute_id' => $_GET['edit']), array('%s', '%s'));
            do_action('fflcommerce_attribute_admin_edit_after_update', $edit, $attribute_label, $attribute_type);
        }
        wp_safe_redirect(get_admin_url() . 'edit.php?post_type=product&page=fflcommerce_attributes');
        exit;
    } elseif (isset($_GET['delete'])) {
        $delete = absint($_GET['delete']);
        check_admin_referer('fflcommerce-delete-attribute_' . $delete);
        if ($delete > 0) {
            $att_name = $wpdb->get_var($wpdb->prepare("SELECT attribute_name FROM " . $wpdb->prefix . "fflcommerce_attribute_taxonomies WHERE attribute_id = %d", $delete));
            if ($att_name && $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->prefix . "fflcommerce_attribute_taxonomies WHERE attribute_id = %d", $delete))) {
                $taxonomy = 'pa_' . sanitize_title($att_name);
                // Old taxonomy prefix left in for backwards compatibility
                if (taxonomy_exists($taxonomy)) {
                    $terms = get_terms($taxonomy, 'orderby=name&hide_empty=0');
                    foreach ($terms as $term) {
                        wp_delete_term($term->term_id, $taxonomy);
                    }
                }
                do_action('fflcommerce_attribute_admin_delete_after', $delete, $att_name);
                wp_safe_redirect(get_admin_url() . 'edit.php?post_type=product&page=fflcommerce_attributes');
                exit;
            }
        }
    }
}
Esempio n. 11
0
 public function __construct()
 {
     parent::__construct();
     $options = FFLCommerce_Base::get_options();
     $this->id = 'local_pickup';
     $this->enabled = $options->get('fflcommerce_local_pickup_enabled');
     $this->title = $options->get('fflcommerce_local_pickup_title');
     $this->fee = $options->get('fflcommerce_local_pickup_handling_fee');
     $this->availability = $options->get('fflcommerce_local_pickup_availability');
     $this->countries = $options->get('fflcommerce_local_pickup_countries');
     $session = fflcommerce_session::instance();
     if (isset($session->chosen_shipping_method_id) && $session->chosen_shipping_method_id == $this->id) {
         $this->chosen = true;
     }
     add_action('fflcommerce_settings_scripts', array($this, 'admin_scripts'));
 }
 public static function send_mail($hook, array $args = array(), $to)
 {
     if (self::can_call_next_action() == false) {
         return;
     }
     $options = \FFLCommerce_Base::get_options();
     $allowed_templates = $options->get('fflcommerce_emails');
     if (!$allowed_templates[$hook]) {
         return;
     }
     foreach ($allowed_templates[$hook] as $post_id) {
         $post = get_post($post_id);
         if (!empty($post) && $post->post_status == 'publish') {
             $headers = array('MIME-Version: 1.0', 'Content-Type: text/html; charset=UTF-8', 'From: "' . self::get_options()->get('fflcommerce_email_from_name') . '" <' . self::get_options()->get('fflcommerce_email') . '>');
             $title = get_post_meta($post_id, 'fflcommerce_email_subject', true);
             $post->post_title = empty($title) ? $post->post_title : $title;
             $post = self::filter_post($post, $args);
             $content = $post->post_content;
             $footer = $options->get('fflcommerce_email_footer');
             if (FFLCommerce_Base::get_options()->get('fflcommerce_enable_html_emails', 'no') == 'no') {
                 $template = nl2br(wptexturize($content));
                 if (!empty($footer)) {
                     $template .= '<br/><br/>' . $footer;
                 }
             } else {
                 $path = locate_template(array('fflcommerce/emails/layout.html'));
                 if (empty($path)) {
                     $path = FFLCOMMERCE_DIR . '/templates/emails/layout.html';
                 }
                 if (!empty($footer)) {
                     $footer .= '<br/>';
                 }
                 $footer .= sprintf(_x('Powered by <a href="%s">FFL Commerce</a> - an e-Commerce plugin built on WordPress', 'emails', 'fflcommerce'), 'http://www.fflcommerce.com');
                 $title = str_replace('[' . get_bloginfo('name') . '] ', '', $post->post_title);
                 $template = file_get_contents($path);
                 $template = str_replace('{heading}', $title, $template);
                 $template = str_replace('{content}', $content, $template);
                 $template = str_replace('{footer}', apply_filters('fflcommerce_email_footer', $footer), $template);
             }
             wp_mail($to, $post->post_title, $template, $headers);
         }
     }
 }
/**
 * Format decimal numbers according to current settings.
 *
 * @param  float|string $number Expects either a float or a string with a decimal separator only (no thousands)
 * @param  mixed $dp number of decimal points to use, blank to use configured decimals or false to avoid all rounding.
 * @param  boolean $trim_zeros from end of string
 * @return string
 */
function fflcommerce_format_decimal($number, $dp = false, $trim_zeros = false)
{
    $locale = localeconv();
    $options = FFLCommerce_Base::get_options();
    $decimals = array($options->get('fflcommerce_price_decimal_sep'), $locale['decimal_point'], $locale['mon_decimal_point']);
    // Remove locale from string
    if (!is_float($number)) {
        $number = fflcommerce_clean(str_replace($decimals, '.', $number));
    }
    if ($dp !== false) {
        $dp = intval($dp == "" ? $options->get('fflcommerce_price_num_decimals') : $dp);
        $number = number_format(floatval($number), $dp, '.', '');
        // DP is false - don't use number format, just return a string in our format
    } elseif (is_float($number)) {
        $number = fflcommerce_clean(str_replace($decimals, '.', strval($number)));
    }
    if ($trim_zeros && strstr($number, '.')) {
        $number = rtrim(rtrim($number, '0'), '.');
    }
    return $number;
}
Esempio n. 14
0
 /**
  * Format Bank information to display in emails
  **/
 public static function get_bank_details()
 {
     $title = FFLCommerce_Base::get_options()->get('fflcommerce_bank_transfer_title');
     $description = FFLCommerce_Base::get_options()->get('fflcommerce_bank_transfer_description');
     $bank_name = FFLCommerce_Base::get_options()->get('fflcommerce_bank_transfer_bank_name');
     $acc_number = FFLCommerce_Base::get_options()->get('fflcommerce_bank_transfer_acc_number');
     $account_holder = FFLCommerce_Base::get_options()->get('fflcommerce_bank_transfer_account_holder');
     $sort_code = FFLCommerce_Base::get_options()->get('fflcommerce_bank_transfer_sort_code');
     $iban = FFLCommerce_Base::get_options()->get('fflcommerce_bank_transfer_iban');
     $bic = FFLCommerce_Base::get_options()->get('fflcommerce_bank_transfer_bic');
     $additional = FFLCommerce_Base::get_options()->get('fflcommerce_bank_transfer_additional');
     $bank_info = null;
     if ($description) {
         $bank_info .= wpautop(wptexturize($description)) . PHP_EOL;
     }
     if ($bank_name) {
         $bank_info .= __('Bank Name', 'fflcommerce') . ": \t" . wptexturize($bank_name) . PHP_EOL;
     }
     if ($acc_number) {
         $bank_info .= __('Account Number', 'fflcommerce') . ":\t " . wptexturize($acc_number) . PHP_EOL;
     }
     if ($account_holder) {
         $bank_info .= __('Account Holder', 'fflcommerce') . ":\t " . wptexturize($account_holder) . PHP_EOL;
     }
     if ($sort_code) {
         $bank_info .= __('Sort Code', 'fflcommerce') . ":\t" . wptexturize($sort_code) . PHP_EOL;
     }
     if ($iban) {
         $bank_info .= __('IBAN', 'fflcommerce') . ": \t\t" . wptexturize($iban) . PHP_EOL;
     }
     if ($bic) {
         $bank_info .= __('BIC', 'fflcommerce') . ": \t\t " . wptexturize($bic) . PHP_EOL;
     }
     if ($additional) {
         $bank_info .= wpautop(__('Additional Information', 'fflcommerce') . ": " . PHP_EOL . wpautop(wptexturize($additional)));
     }
     if ($bank_info) {
         return wpautop($bank_info);
     }
 }
Esempio n. 15
0
function fflcommerce_order_tracking($atts)
{
    extract(shortcode_atts(array(), $atts));
    global $post;
    $fflcommerce_options = FFLCommerce_Base::get_options();
    if ($_POST) {
        $order = new fflcommerce_order();
        $order->id = !empty($_POST['orderid']) ? $_POST['orderid'] : 0;
        if (isset($_POST['order_email']) && $_POST['order_email']) {
            $order_email = trim($_POST['order_email']);
        } else {
            $order_email = '';
        }
        if (!fflcommerce::verify_nonce('order_tracking')) {
            echo '<p>' . __('You have taken too long. Please refresh the page and retry.', 'fflcommerce') . '</p>';
        } elseif ($order->id && $order_email && $order->get_order(apply_filters('fflcommerce_shortcode_order_tracking_order_id', $order->id))) {
            if ($order->billing_email == $order_email) {
                echo '<p>' . sprintf(__('Order %s which was made %s ago and has the status "%s"', 'fflcommerce'), $order->get_order_number(), human_time_diff(strtotime($order->order_date), current_time('timestamp')), __($order->status, 'fflcommerce'));
                if ($order->status == 'completed') {
                    $completed = (array) get_post_meta($order->id, '_js_completed_date', true);
                    if (!empty($completed)) {
                        $completed = $completed[0];
                    } else {
                        $completed = '';
                    }
                    // shouldn't happen, reset to be sure
                    echo sprintf(__(' was completed %s ago', 'fflcommerce'), human_time_diff(strtotime($completed), current_time('timestamp')));
                }
                echo '.</p>';
                do_action('fflcommerce_tracking_details_info', $order);
                ?>
				<?php 
                do_action('fflcommerce_before_track_order_details', $order->id);
                ?>
				<h2><?php 
                _e('Order Details', 'fflcommerce');
                ?>
</h2>
				<table class="shop_table">
					<thead>
						<tr>
							<th><?php 
                _e('ID/SKU', 'fflcommerce');
                ?>
</th>
							<th><?php 
                _e('Title', 'fflcommerce');
                ?>
</th>
							<th><?php 
                _e('Price', 'fflcommerce');
                ?>
</th>
							<th><?php 
                _e('Quantity', 'fflcommerce');
                ?>
</th>
						</tr>
					</thead>
					<tfoot>
                        <tr>
                            <?php 
                if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                    ?>
                                <td colspan="3"><?php 
                    _e('Retail Price', 'fflcommerce');
                    ?>
</td>
                            <?php 
                } else {
                    ?>
                                <td colspan="3"><?php 
                    _e('Subtotal', 'fflcommerce');
                    ?>
</td>
                            <?php 
                }
                ?>
                                <td><?php 
                echo $order->get_subtotal_to_display();
                ?>
</td>
                        </tr>
                        <?php 
                if ($order->order_shipping > 0) {
                    ?>
                            <tr>
                                <td colspan="3"><?php 
                    _e('Shipping', 'fflcommerce');
                    ?>
</td>
                                <td><?php 
                    echo $order->get_shipping_to_display();
                    ?>
</td>
                            </tr>
                            <?php 
                }
                do_action('fflcommerce_processing_fee_after_shipping');
                if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                    ?>
                            <tr class="discount">
                                <td colspan="3"><?php 
                    _e('Discount', 'fflcommerce');
                    ?>
</td>
                                <td>-<?php 
                    echo fflcommerce_price($order->order_discount);
                    ?>
</td>
                            </tr>
                            <?php 
                }
                if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                    ?>
                            <tr>
                                <td colspan="3"><?php 
                    _e('Subtotal', 'fflcommerce');
                    ?>
</td>
                                <td><?php 
                    echo fflcommerce_price($order->order_discount_subtotal);
                    ?>
</td>
                            </tr>
                            <?php 
                }
                if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes') {
                    foreach ($order->get_tax_classes() as $tax_class) {
                        if ($order->show_tax_entry($tax_class)) {
                            ?>
                                    <tr>
                                        <td colspan="3"><?php 
                            echo $order->get_tax_class_for_display($tax_class) . ' (' . (double) $order->get_tax_rate($tax_class) . '%):';
                            ?>
</td>
                                        <td><?php 
                            echo $order->get_tax_amount($tax_class);
                            ?>
</td>
                                    </tr>
                                    <?php 
                        }
                    }
                }
                ?>
						<?php 
                if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'no' && $order->order_discount > 0) {
                    ?>
<tr class="discount">
							<td colspan="3"><?php 
                    _e('Discount', 'fflcommerce');
                    ?>
</td>
							<td>-<?php 
                    echo fflcommerce_price($order->order_discount);
                    ?>
</td>
						</tr><?php 
                }
                ?>
						<tr>
							<td colspan="3"><strong><?php 
                _e('Grand Total', 'fflcommerce');
                ?>
</strong></td>
							<td><strong><?php 
                echo fflcommerce_price($order->order_total);
                ?>
</strong></td>
						</tr>
					</tfoot>
					<tbody>
						<?php 
                foreach ($order->items as $order_item) {
                    if (isset($order_item['variation_id']) && $order_item['variation_id'] > 0) {
                        $_product = new fflcommerce_product_variation($order_item['variation_id']);
                    } else {
                        $_product = new fflcommerce_product($order_item['id']);
                    }
                    echo '<tr>';
                    echo '<td>' . $_product->sku . '</td>';
                    echo '<td class="product-name">' . $_product->get_title();
                    if ($_product instanceof fflcommerce_product_variation) {
                        echo fflcommerce_get_formatted_variation($_product, $order_item['variation']);
                    }
                    do_action('fflcommerce_display_item_meta_data', $order_item);
                    echo '</td>';
                    echo '<td>' . fflcommerce_price($order_item['cost']) . '</td>';
                    echo '<td>' . $order_item['qty'] . '</td>';
                    echo '</tr>';
                }
                ?>
					</tbody>
				</table>
				<?php 
                do_action('fflcommerce_after_track_order_details', $order->id);
                ?>

				<div style="width: 49%; float:left;">
					<h2><?php 
                _e('Billing Address', 'fflcommerce');
                ?>
</h2>
					<p><?php 
                $address = $order->billing_first_name . ' ' . $order->billing_last_name . '<br/>';
                if ($order->billing_company) {
                    $address .= $order->billing_company . '<br/>';
                }
                $address .= $order->formatted_billing_address;
                echo $address;
                ?>
</p>
				</div>
				<div style="width: 49%; float:right;">
					<h2><?php 
                _e('Shipping Address', 'fflcommerce');
                ?>
</h2>
					<p><?php 
                $address = $order->shipping_first_name . ' ' . $order->shipping_last_name . '<br/>';
                if ($order->shipping_company) {
                    $address .= $order->shipping_company . '<br/>';
                }
                $address .= $order->formatted_shipping_address;
                echo $address;
                ?>
</p>
				</div>
				<div class="clear"></div>
				<?php 
            } else {
                echo '<p>' . __('Sorry, we could not find that order id in our database. <a href="' . get_permalink($post->ID) . '">Want to retry?</a>', 'fflcommerce') . '</p>';
            }
        } else {
            echo '<p>' . sprintf(__('Sorry, we could not find that order id in our database. <a href="%s">Want to retry?</a></p>', 'fflcommerce'), get_permalink($post->ID));
        }
    } else {
        ?>
		<form action="<?php 
        echo esc_url(get_permalink($post->ID));
        ?>
" method="post" class="track_order">

			<p><?php 
        _e('To track your order please enter your Order ID and email address in the boxes below and press return. This was given to you on your receipt and in the confirmation email you should have received.', 'fflcommerce');
        ?>
</p>

			<p class="form-row form-row-first"><label for="orderid"><?php 
        _e('Order ID', 'fflcommerce');
        ?>
</label> <input class="input-text" type="text" name="orderid" id="orderid" placeholder="<?php 
        _e('Found in your order confirmation email.', 'fflcommerce');
        ?>
" /></p>
			<p class="form-row form-row-last"><label for="order_email"><?php 
        _e('Billing Email', 'fflcommerce');
        ?>
</label> <input class="input-text" type="text" name="order_email" id="order_email" placeholder="<?php 
        _e('Email you used during checkout.', 'fflcommerce');
        ?>
" /></p>
			<div class="clear"></div>
			<p class="form-row"><input type="submit" class="button" name="track" value="<?php 
        _e('Track"', 'fflcommerce');
        ?>
" /></p>
			<?php 
        fflcommerce::nonce_field('order_tracking');
        ?>
		</form>
		<?php 
    }
}
Esempio n. 16
0
function fflcommerce_sale_products($atts)
{
    global $columns, $per_page, $paged;
    extract(shortcode_atts(array('per_page' => FFLCommerce_Base::get_options()->get('fflcommerce_catalog_per_page'), 'columns' => FFLCommerce_Base::get_options()->get('fflcommerce_catalog_columns'), 'orderby' => FFLCommerce_Base::get_options()->get('fflcommerce_catalog_sort_orderby'), 'order' => FFLCommerce_Base::get_options()->get('fflcommerce_catalog_sort_direction'), 'pagination' => false), $atts));
    $ids = fflcommerce_product::get_product_ids_on_sale();
    if (empty($ids)) {
        $ids = array('0');
    }
    $args = array('post_status' => 'publish', 'post_type' => 'product', 'posts_per_page' => $per_page, 'orderby' => $orderby, 'order' => $order, 'paged' => $paged, 'post__in' => $ids);
    query_posts($args);
    ob_start();
    fflcommerce_get_template_part('loop', 'shop');
    if ($pagination) {
        do_action('fflcommerce_pagination');
    }
    wp_reset_postdata();
    return ob_get_clean();
}
 protected function add_rate($price, $service_name)
 {
     $price += empty($this->fee) ? 0 : $this->get_fee($this->fee, fflcommerce_cart::$cart_contents_total_ex_dl);
     $tax = 0;
     if (FFLCommerce_Base::get_options()->get('fflcommerce_calc_taxes') == 'yes' && $this->tax_status == 'taxable' && $price > 0) {
         $tax = $this->calculate_shipping_tax($price);
     }
     // changed for 1.4.5 since there are instances where a shipping method may want to provide their own rules for
     // when shipping is free...that cannot be obtained within the free shipping method itself.
     if ($price >= 0) {
         $this->rates[] = array('service' => $service_name, 'price' => $price, 'tax' => $tax);
     }
 }
 /**
  * Validate the checkout
  */
 public function validate_checkout()
 {
     if (fflcommerce_cart::is_empty()) {
         fflcommerce::add_error(sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage &rarr;</a>', 'fflcommerce'), home_url()));
     }
     // Process Discount Codes
     if (!empty($_POST['coupon_code'])) {
         $coupon = sanitize_title($_POST['coupon_code']);
         fflcommerce_cart::add_discount($coupon);
     }
     foreach (fflcommerce_cart::get_coupons() as $coupon) {
         fflcommerce_cart::is_valid_coupon($coupon);
     }
     // Checkout fields
     $this->posted['shipping_method'] = '';
     $this->posted['shipping_service'] = '';
     if (isset($_POST['shipping_method'])) {
         $shipping_method = fflcommerce_clean($_POST['shipping_method']);
         $shipping_data = explode(':', $shipping_method);
         $this->posted['shipping_method'] = $shipping_data[0];
         $this->posted['shipping_service'] = $shipping_data[1];
     }
     $this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? fflcommerce_clean($_POST['shiptobilling']) : '';
     $this->posted['payment_method'] = isset($_POST['payment_method']) ? fflcommerce_clean($_POST['payment_method']) : '';
     $this->posted['order_comments'] = isset($_POST['order_comments']) ? fflcommerce_clean($_POST['order_comments']) : '';
     $this->posted['terms'] = isset($_POST['terms']) ? fflcommerce_clean($_POST['terms']) : '';
     $this->posted['create_account'] = isset($_POST['create_account']) ? fflcommerce_clean($_POST['create_account']) : '';
     $this->posted['account_username'] = isset($_POST['account_username']) ? fflcommerce_clean($_POST['account_username']) : '';
     $this->posted['account_password'] = isset($_POST['account_password']) ? fflcommerce_clean($_POST['account_password']) : '';
     $this->posted['account_password_2'] = isset($_POST['account_password_2']) ? fflcommerce_clean($_POST['account_password_2']) : '';
     if (fflcommerce_cart::get_total(false) == 0) {
         $this->posted['payment_method'] = 'no_payment';
     }
     // establish customer billing and shipping locations
     if (fflcommerce_cart::ship_to_billing_address_only()) {
         $this->posted['shiptobilling'] = 'true';
     }
     $country = isset($_POST['billing_country']) ? fflcommerce_clean($_POST['billing_country']) : '';
     $state = isset($_POST['billing_state']) ? fflcommerce_clean($_POST['billing_state']) : '';
     $allowed_countries = FFLCommerce_Base::get_options()->get('fflcommerce_allowed_countries');
     if ($allowed_countries === 'specific') {
         $specific_countries = FFLCommerce_Base::get_options()->get('fflcommerce_specific_allowed_countries');
         if (!in_array($country, $specific_countries)) {
             fflcommerce::add_error(__('Invalid billing country.', 'fflcommerce'));
             return;
         }
     }
     if (fflcommerce_countries::country_has_states($country)) {
         $states = fflcommerce_countries::get_states($country);
         if (!in_array($state, array_keys($states))) {
             fflcommerce::add_error(__('Invalid billing state.', 'fflcommerce'));
             return;
         }
     }
     $postcode = isset($_POST['billing_postcode']) ? fflcommerce_clean($_POST['billing_postcode']) : '';
     $ship_to_billing = FFLCommerce_Base::get_options()->get('fflcommerce_ship_to_billing_address_only') == 'yes';
     fflcommerce_customer::set_location($country, $state, $postcode);
     if (FFLCommerce_Base::get_options()->get('fflcommerce_calc_shipping') == 'yes') {
         if ($ship_to_billing || !empty($_POST['shiptobilling'])) {
             fflcommerce_customer::set_shipping_location($country, $state, $postcode);
         } else {
             $country = isset($_POST['shipping_country']) ? fflcommerce_clean($_POST['shipping_country']) : '';
             $state = isset($_POST['shipping_state']) ? fflcommerce_clean($_POST['shipping_state']) : '';
             $postcode = isset($_POST['shipping_postcode']) ? fflcommerce_clean($_POST['shipping_postcode']) : '';
             if ($allowed_countries === 'specific') {
                 $specific_countries = FFLCommerce_Base::get_options()->get('fflcommerce_specific_allowed_countries');
                 if (!in_array($country, $specific_countries)) {
                     fflcommerce::add_error(__('Invalid shipping country.', 'fflcommerce'));
                     return;
                 }
             }
             if (fflcommerce_countries::country_has_states($country)) {
                 $states = fflcommerce_countries::get_states($country);
                 if (!in_array($state, array_keys($states))) {
                     fflcommerce::add_error(__('Invalid shipping state.', 'fflcommerce'));
                     return;
                 }
             }
             fflcommerce_customer::set_shipping_location($country, $state, $postcode);
         }
     }
     // Billing Information
     foreach ($this->billing_fields as $field) {
         $field = apply_filters('fflcommerce_billing_field', $field);
         $this->posted[$field['name']] = isset($_POST[$field['name']]) ? fflcommerce_clean($_POST[$field['name']]) : '';
         // Format
         if (isset($field['format'])) {
             switch ($field['format']) {
                 case 'postcode':
                     $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']]));
                     break;
             }
         }
         // Required
         if ($field['name'] == 'billing_state' && fflcommerce_customer::has_valid_shipping_state()) {
             $field['required'] = false;
         }
         if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) {
             fflcommerce::add_error($field['label'] . __(' (billing) is a required field.', 'fflcommerce'));
         }
         if ($field['name'] == 'billing_euvatno') {
             $vatno = isset($this->posted['billing_euvatno']) ? $this->posted['billing_euvatno'] : '';
             $vatno = str_replace(' ', '', $vatno);
             $country = fflcommerce_tax::get_customer_country();
             // strip any country code from the beginning of the number
             if (strpos($vatno, $country) === 0) {
                 $vatno = substr($vatno, strlen($country));
             }
             if ($vatno != '') {
                 $url = 'http://isvat.appspot.com/' . $country . '/' . $vatno . '/';
                 $httpRequest = curl_init();
                 curl_setopt($httpRequest, CURLOPT_FAILONERROR, true);
                 curl_setopt($httpRequest, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($httpRequest, CURLOPT_HEADER, false);
                 curl_setopt($httpRequest, CURLOPT_URL, $url);
                 $result = curl_exec($httpRequest);
                 curl_close($httpRequest);
                 if ($result === 'false') {
                     fflcommerce_log('EU VAT validation error with URL: ' . $url);
                     fflcommerce::add_error($field['label'] . __(' (billing) is not a valid VAT Number.  Leave it blank to disable VAT validation. (VAT may be charged depending on your location)', 'fflcommerce'));
                 } else {
                     $this->valid_euvatno = fflcommerce_countries::get_base_country() != fflcommerce_tax::get_customer_country() && fflcommerce_countries::is_eu_country(fflcommerce_tax::get_customer_country());
                 }
             }
         }
         // Validation
         if (isset($field['validate']) && !empty($this->posted[$field['name']])) {
             switch ($field['validate']) {
                 case 'phone':
                     if (!fflcommerce_validation::is_phone($this->posted[$field['name']])) {
                         fflcommerce::add_error($field['label'] . __(' (billing) is not a valid number.', 'fflcommerce'));
                     }
                     break;
                 case 'email':
                     if (!fflcommerce_validation::is_email($this->posted[$field['name']])) {
                         fflcommerce::add_error($field['label'] . __(' (billing) is not a valid email address.', 'fflcommerce'));
                     }
                     break;
                 case 'postcode':
                     if (!fflcommerce_validation::is_postcode($this->posted[$field['name']], $_POST['billing_country'])) {
                         fflcommerce::add_error($field['label'] . __(' (billing) is not a valid postcode/ZIP.', 'fflcommerce'));
                     } else {
                         $this->posted[$field['name']] = fflcommerce_validation::format_postcode($this->posted[$field['name']], $_POST['billing_country']);
                     }
                     break;
             }
         }
     }
     // Shipping Information
     if (fflcommerce_shipping::is_enabled() && !fflcommerce_cart::ship_to_billing_address_only() && empty($this->posted['shiptobilling'])) {
         foreach ($this->shipping_fields as $field) {
             $field = apply_filters('fflcommerce_shipping_field', $field);
             if (isset($_POST[$field['name']])) {
                 $this->posted[$field['name']] = fflcommerce_clean($_POST[$field['name']]);
             } else {
                 $this->posted[$field['name']] = '';
             }
             // Format
             if (isset($field['format'])) {
                 switch ($field['format']) {
                     case 'postcode':
                         $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']]));
                         break;
                 }
             }
             // Required
             if ($field['name'] == 'shipping_state' && fflcommerce_customer::has_valid_shipping_state()) {
                 $field['required'] = false;
             }
             if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) {
                 fflcommerce::add_error($field['label'] . __(' (shipping) is a required field.', 'fflcommerce'));
             }
             // Validation
             if (isset($field['validate']) && !empty($this->posted[$field['name']])) {
                 switch ($field['validate']) {
                     case 'postcode':
                         if (!fflcommerce_validation::is_postcode($this->posted[$field['name']], $country)) {
                             fflcommerce::add_error($field['label'] . __(' (shipping) is not a valid postcode/ZIP.', 'fflcommerce'));
                         } else {
                             $this->posted[$field['name']] = fflcommerce_validation::format_postcode($this->posted[$field['name']], $country);
                         }
                         break;
                 }
             }
         }
     }
     if ($this->must_register && empty($this->posted['create_account'])) {
         fflcommerce::add_error(__('Sorry, you must agree to creating an account', 'fflcommerce'));
     }
     if ($this->must_register || empty($user_id) && $this->posted['create_account']) {
         if (!$this->show_signup) {
             fflcommerce::add_error(__('Sorry, the shop owner has disabled guest purchases.', 'fflcommerce'));
         }
         if (empty($this->posted['account_username'])) {
             fflcommerce::add_error(__('Please enter an account username.', 'fflcommerce'));
         }
         if (empty($this->posted['account_password'])) {
             fflcommerce::add_error(__('Please enter an account password.', 'fflcommerce'));
         }
         if ($this->posted['account_password_2'] !== $this->posted['account_password']) {
             fflcommerce::add_error(__('Passwords do not match.', 'fflcommerce'));
         }
         // Check the username
         if (!validate_username($this->posted['account_username'])) {
             fflcommerce::add_error(__('Invalid email/username.', 'fflcommerce'));
         } elseif (username_exists($this->posted['account_username'])) {
             fflcommerce::add_error(__('An account is already registered with that username. Please choose another.', 'fflcommerce'));
         }
         // Check the e-mail address
         if (email_exists($this->posted['billing_email'])) {
             fflcommerce::add_error(__('An account is already registered with your email address. Please login.', 'fflcommerce'));
         }
     }
     // Terms
     if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && fflcommerce_get_page_id('terms') > 0) {
         fflcommerce::add_error(__('You must accept our Terms &amp; Conditions.', 'fflcommerce'));
     }
     if (fflcommerce_cart::needs_shipping()) {
         // Shipping Method
         $available_methods = fflcommerce_shipping::get_available_shipping_methods();
         if (!isset($available_methods[$this->posted['shipping_method']])) {
             fflcommerce::add_error(__('Invalid shipping method.', 'fflcommerce'));
         }
     }
 }
Esempio n. 19
0
function fflcommerce_install_emails()
{
    $default_emails = array('new_order_admin_notification', 'customer_order_status_pending_to_processing', 'customer_order_status_pending_to_on-hold', 'customer_order_status_pending_to_waiting-for-payment', 'customer_order_status_on-hold_to_processing', 'customer_order_status_completed', 'customer_order_status_refunded', 'send_customer_invoice', 'low_stock_notification', 'no_stock_notification', 'product_on_backorder_notification');
    $invoice = '
		[is_cheque]
			<p>' . _x('We are waiting for your cheque before we can start processing this order.', 'emails', 'fflcommerce') . '</p>
			<p>[cheque_info]</p>
			<p>Total value: [total]</p>
		[else]
		[is_bank_transfer]
			<p>' . _x('We are waiting for your payment before we can start processing this order.', 'emails', 'fflcommerce') . '</p>
			<h4>' . _x('Bank details', 'emails', 'fflcommerce') . '</h4>
			[bank_info]
			<p>Total value: [total]</p>
		[else]
		[is_local_pickup]
		<h4>' . _x('Your order is being prepared', 'emails', 'fflcommerce') . '</h4>
		<p>' . _x('We are preparing your order, you will receive another email when we will be ready and awaiting for you to pick it up.', 'emails', 'fflcommerce') . '</p>
		[else]
		[is_cash_on_delivery]
		<h4>' . _x('Order will be dispatched shortly', 'emails', 'fflcommerce') . '</h4>
		<p>' . _x('Your order is being processed and will be dispatched to you as soon as possible. Please prepare exact change to pay when package arrives.', 'emails', 'fflcommerce') . '</p>
		[/is_cash_on_delivery]
		[/is_local_pickup]
		[/is_bank_transfer]
		[/is_cheque]
		<h4>' . _x('Order [order_number] on [order_date]', 'emails', 'fflcommerce') . '</h4>
		[order_items_table]
		<h4>' . _x('Customer details', 'emails', 'fflcommerce') . '</h4>
		<p>' . _x('Email:', 'emails', 'fflcommerce') . ' <a href="mailto:[billing_email]">[billing_email]</a></p>
		<p>' . _x('Phone:', 'emails', 'fflcommerce') . ' [billing_phone]</p>
		<table class="customer">
			<thead>
				<tr>
					<td><strong>' . _x('Billing address', 'emails', 'fflcommerce') . '</strong></td>
					<td><strong>' . _x('Shipping address', 'emails', 'fflcommerce') . '</strong></td>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>
						[billing_first_name] [billing_last_name]<br />
						[billing_address_1][billing_address_2], [value][/billing_address_2]<br />
						[billing_city], [billing_postcode]<br />
						[billing_state]<br />
						[billing_country]
					</td>
					<td>
						[shipping_first_name] [shipping_last_name]<br />
						[shipping_address_1][shipping_address_2], [value][/shipping_address_2]<br />
						[shipping_city], [shipping_postcode]<br />
						[shipping_state]<br />
						[shipping_country]
					</td>
				</tr>
			</tbody>
		</table>
		[customer_note]
		<h4>' . _x('Customer note', 'emails', 'fflcommerce') . '</h4>
		<p>[value]</p>
		[/customer_note]
	';
    $title = '';
    $message = '';
    $post_title = '';
    foreach ($default_emails as $email) {
        switch ($email) {
            case 'new_order_admin_notification':
                $post_title = __('New order admin notification', 'fflcommerce');
                $title = __('[[shop_name]] New Customer Order', 'fflcommerce');
                $message = __('<p>You have received an order from [billing_first_name] [billing_last_name].</p><p>Current order status: <strong>[order_status]</strong></p>', 'fflcommerce') . $invoice;
                break;
            case 'customer_order_status_pending_to_on-hold':
                $post_title = __('Customer order status pending to on-hold', 'fflcommerce');
                $title = __('[[shop_name]] Order Received', 'fflcommerce');
                $message = __('<p>Thank you, we have received your order.</p>', 'fflcommerce') . $invoice;
                break;
            case 'customer_order_status_pending_to_waiting-for-payment':
                $post_title = __('Customer order status pending to waiting for payment', 'fflcommerce');
                $title = __('[[shop_name]] Order Received - waiting for payment', 'fflcommerce');
                $message = __('<p>Thank you, we have received your order.</p>', 'fflcommerce') . $invoice;
                break;
            case 'customer_order_status_pending_to_processing':
                $post_title = __('Customer order status pending to processing', 'fflcommerce');
                $title = __('[[shop_name]] Order Received', 'fflcommerce');
                $message = __('<p>Thank you, we are now processing your order.<br/>', 'fflcommerce') . $invoice;
                break;
            case 'customer_order_status_on-hold_to_processing':
                $post_title = __('Customer order status on-hold to processing', 'fflcommerce');
                $title = __('[[shop_name]] Order Received', 'fflcommerce');
                $message = __('<p>Thank you, we are now processing your order.<br/>', 'fflcommerce') . $invoice;
                break;
            case 'customer_order_status_completed':
                $post_title = __('Customer order status completed', 'fflcommerce');
                $title = __('[[shop_name]] Order Complete', 'fflcommerce');
                $message = __('<p>Your order is complete.<br/>', 'fflcommerce') . $invoice;
                break;
            case 'customer_order_status_refunded':
                $post_title = __('Customer order status refunded', 'fflcommerce');
                $title = __('[[shop_name]] Order Refunded', 'fflcommerce');
                $message = __('<p>Your order has been refunded.</p>', 'fflcommerce') . $invoice;
                break;
            case 'send_customer_invoice':
                $post_title = __('Send customer invoice', 'fflcommerce');
                $title = __('Invoice for Order: [order_number]', 'fflcommerce');
                $message = $invoice;
                break;
            case 'low_stock_notification':
                $post_title = __('Low stock notification', 'fflcommerce');
                $title = __('[[shop_name]] Product low in stock', 'fflcommerce');
                $message = __('<p>#[product_id] [product_name] ([sku]) is low in stock.</p>', 'fflcommerce');
                break;
            case 'no_stock_notification':
                $post_title = __('No stock notification', 'fflcommerce');
                $title = __('[[shop_name]] Product out of stock', 'fflcommerce');
                $message = __('<p>#[product_id] [product_name] ([sku]) is out of stock.</p>', 'fflcommerce');
                break;
            case 'product_on_backorder_notification':
                $post_title = __('Product on backorder notification', 'fflcommerce');
                $title = __('[[shop_name]] Product Backorder on Order: [order_number].', 'fflcommerce');
                $message = __('<p>#[product_id] [product_name] ([sku]) was found to be on backorder.</p>', 'fflcommerce') . $invoice;
                break;
        }
        $post_data = array('post_content' => $message, 'post_title' => $post_title, 'post_status' => 'publish', 'post_type' => 'shop_email', 'post_author' => 1, 'ping_status' => 'closed', 'comment_status' => 'closed');
        $post_id = wp_insert_post($post_data);
        update_post_meta($post_id, 'fflcommerce_email_subject', $title);
        if ($email == 'new_order_admin_notification') {
            fflcommerce_emails::set_actions($post_id, array('admin_order_status_pending_to_processing', 'admin_order_status_pending_to_completed', 'admin_order_status_pending_to_on-hold', 'admin_order_status_pending_to_waiting-for-payment'));
            update_post_meta($post_id, 'fflcommerce_email_actions', array('admin_order_status_pending_to_processing', 'admin_order_status_pending_to_completed', 'admin_order_status_pending_to_on-hold', 'admin_order_status_pending_to_waiting-for-payment'));
        } else {
            fflcommerce_emails::set_actions($post_id, array($email));
            update_post_meta($post_id, 'fflcommerce_email_actions', array($email));
        }
    }
    \FFLCommerce_Base::get_options()->set('fflcommerce_enable_html_emails', 'yes');
}
Esempio n. 20
0
    /**
     * Generate the skrill button link
     **/
    public function generate_skrill_form()
    {
        $order_id = $_GET['orderId'];
        $order = new fflcommerce_order($order_id);
        $skrill_adr = 'https://www.moneybookers.com/app/payment.pl';
        $shipping_name = explode(' ', $order->shipping_method);
        $order_total = trim($order->order_total, 0);
        if (substr($order_total, -1) == '.') {
            $order_total = str_replace('.', '', $order_total);
        }
        // filter redirect page
        $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks'));
        $skrill_args = array('merchant_fields' => 'partner', 'partner' => 'FFLCommerce', 'pay_to_email' => $this->email, 'recipient_description' => get_bloginfo('name'), 'transaction_id' => $order_id, 'return_url' => get_permalink($checkout_redirect), 'return_url_text' => 'Return to Merchant', 'new_window_redirect' => 0, 'prepare_only' => 0, 'return_url_target' => 1, 'cancel_url' => trailingslashit(get_bloginfo('url')) . '?skrillListener=skrill_cancel', 'cancel_url_target' => 1, 'status_url' => trailingslashit(get_bloginfo('url')) . '?skrillListener=skrill_status', 'language' => $this->getLocale(), 'hide_login' => 1, 'confirmation_note' => __('Thank you for shopping', 'fflcommerce'), 'pay_from_email' => $order->billing_email, 'firstname' => $order->billing_first_name, 'lastname' => $order->billing_last_name, 'address' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'phone_number' => $order->billing_phone, 'postal_code' => $order->billing_postcode, 'city' => $order->billing_city, 'state' => $order->billing_state, 'country' => $this->retrieveIOC($this->getLocale()), 'amount' => $order_total, 'currency' => FFLCommerce_Base::get_options()->get_option('fflcommerce_currency'), 'detail1_description' => 'Order ID', 'detail1_text' => $order_id, 'payment_methods' => $this->payment_methods);
        // Cart Contents
        $item_loop = 0;
        if (sizeof($order->items) > 0) {
            foreach ($order->items as $item) {
                if (!empty($item['variation_id'])) {
                    $_product = new fflcommerce_product_variation($item['variation_id']);
                } else {
                    $_product = new fflcommerce_product($item['id']);
                }
                if ($_product->exists() && $item['qty']) {
                    $item_loop++;
                    $skrill_args['item_name_' . $item_loop] = $_product->get_title();
                    $skrill_args['quantity_' . $item_loop] = $item['qty'];
                    $skrill_args['amount_' . $item_loop] = $_product->get_price_with_tax();
                }
            }
        }
        // Shipping Cost
        $item_loop++;
        $skrill_args['item_name_' . $item_loop] = __('Shipping cost', 'fflcommerce');
        $skrill_args['quantity_' . $item_loop] = '1';
        $skrill_args['amount_' . $item_loop] = number_format($order->order_shipping, 2);
        $skrill_args_array = array();
        foreach ($skrill_args as $key => $value) {
            $skrill_args_array[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />';
        }
        // Skirll MD5 concatenation
        $skrill_md = FFLCommerce_Base::get_options()->get_option('fflcommerce_skrill_customer_id') . $skrill_args['transaction_id'] . strtoupper(md5(FFLCommerce_Base::get_options()->get_option('fflcommerce_skrill_secret_word'))) . $order_total . FFLCommerce_Base::get_options()->get_option('fflcommerce_currency') . '2';
        $skrill_md = md5($skrill_md);
        add_post_meta($order_id, '_skrillmd', $skrill_md);
        echo '<form name="moneybookers" id="moneybookers_place_form" action="' . $skrill_adr . '" method="POST">' . implode('', $skrill_args_array) . '</form>';
        echo '<script type="text/javascript">
		//<![CDATA[
    	var paymentform = document.getElementById(\'moneybookers_place_form\');
   		window.onload = paymentform.submit();
		//]]>
		</script>';
        exit;
    }
Esempio n. 21
0
<div id="payment">

	<ul class="payment_methods methods">
		<?php 
$available_gateways = fflcommerce_payment_gateways::get_available_payment_gateways();
if ($available_gateways) {
    $default_gateway = FFLCommerce_Base::get_options()->get_option('fflcommerce_default_gateway');
    if (!empty($default_gateway)) {
        if (array_key_exists($default_gateway, $available_gateways)) {
            $temp = $available_gateways[$default_gateway];
            unset($available_gateways[$default_gateway]);
            array_unshift($available_gateways, $temp);
        }
    }
    $gateway_set = false;
    foreach ($available_gateways as $gateway) {
        /** @var fflcommerce_payment_gateway $gateway */
        if (fflcommerce_checkout::process_gateway($gateway)) {
            if (!$gateway_set) {
                // Chosen Method
                if (sizeof($available_gateways)) {
                    if (isset($_POST['payment_method']) && isset($available_gateways[$_POST['payment_method']])) {
                        $available_gateways[$_POST['payment_method']]->set_current();
                    } else {
                        $gateway->set_current();
                    }
                }
                $gateway_set = true;
            }
            ?>
					<li>
Esempio n. 22
0
 /**
  * Process the product variable meta
  *
  * @param   int $parent_id Product ID
  * @return  void
  */
 public function save($parent_id)
 {
     global $wpdb;
     // Do not run if there are no variations
     if (!isset($_POST['variations'])) {
         return;
     }
     // Get the attributes to be used later
     $attributes = (array) maybe_unserialize(get_post_meta($parent_id, 'product_attributes', true));
     $minimal_price = PHP_INT_MAX;
     foreach ($_POST['variations'] as $ID => $meta) {
         /**
          * Generate a post title of the current variation.
          * Parent Title - [attribute: variation]
          */
         $taxes = array();
         foreach ($meta as $k => $v) {
             if (strstr($k, 'tax_')) {
                 $tax = substr($k, 4);
                 $taxes[] = sprintf('[%s: %s]', $tax, !empty($v) ? $v : 'Any ' . $tax);
             }
         }
         $post_title = !empty($_POST['post_title']) ? $_POST['post_title'] : the_title('', '', false);
         $title = sprintf('%s - %s', $post_title, implode($taxes, ' '));
         /**
          * Prevent duplicate variations
          */
         // Update post data or Add post if new
         if (strpos($ID, '_new')) {
             // check for an existing variation with matching attributes to prevent duplication
             $current_meta = $meta;
             foreach ($current_meta as $current_id => $current_value) {
                 // discard everything but the taxonomies
                 if (strpos($current_id, 'tax_') !== 0) {
                     unset($current_meta[$current_id]);
                 }
             }
             // we now have just the taxonomies in use for this new variation in $current_meta, match them up to others
             $all_variations = $_POST['variations'];
             unset($all_variations[$ID]);
             // we don't need the current new variation
             $duplicate = false;
             foreach ($all_variations as $this_id => $this_meta) {
                 $haystack_meta = $this_meta;
                 foreach ($haystack_meta as $haystack_id => $haystack_value) {
                     // discard everything but the taxonomies
                     if (strpos($haystack_id, 'tax_') !== 0) {
                         unset($haystack_meta[$haystack_id]);
                     }
                 }
                 // we now have the taxonomies only for this haystack variation
                 $result = array_diff($haystack_meta, $current_meta);
                 if (empty($result)) {
                     $duplicate = true;
                 }
             }
             if (!$duplicate) {
                 $ID = wp_insert_post(array('post_title' => !empty($title) ? $title : "#{$parent_id}: Child Variation", 'post_status' => isset($meta['enabled']) ? 'publish' : 'draft', 'post_parent' => $parent_id, 'post_type' => 'product_variation'));
             } else {
                 // silent fail, should put up a message?
             }
         } else {
             $_product = new fflcommerce_product_variation($ID);
             if (FFLCommerce_Base::get_options()->get('fflcommerce_hide_no_stock_product') == 'yes' && $_product->managing_stock()) {
                 if ($meta['stock'] <= fflcommerce_Base::get_options()->get('fflcommerce_notify_no_stock_amount') && $meta['stock'] != '') {
                     unset($meta['enabled']);
                 } else {
                     $meta['enabled'] = true;
                 }
             }
             $wpdb->update($wpdb->posts, array('post_title' => !empty($title) ? $title : "#{$parent_id}: Child Variation", 'post_status' => isset($meta['enabled']) ? 'publish' : 'draft'), array('ID' => $ID));
         }
         // Set the product type
         wp_set_object_terms($ID, sanitize_title($meta['product-type']), 'product_type');
         // Set variation meta data
         $meta['regular_price'] = fflcommerce_sanitize_num($meta['regular_price']);
         if (!empty($meta['regular_price']) && !is_numeric($meta['regular_price'])) {
             add_filter('redirect_post_location', function ($location) {
                 return add_query_arg('fflcommerce_message', 'invalid_variation_price', $location);
             });
             $meta['regular_price'] = 0.0;
         }
         if (empty($meta['regular_price'])) {
             $meta['regular_price'] = null;
         }
         update_post_meta($ID, 'sku', $meta['sku']);
         update_post_meta($ID, 'regular_price', $meta['regular_price']);
         if ($meta['regular_price'] < $minimal_price) {
             $minimal_price = $meta['regular_price'];
         }
         $sale_price = !empty($meta['sale_price']) ? !strstr($meta['sale_price'], '%') ? fflcommerce_sanitize_num($meta['sale_price']) : $meta['sale_price'] : '';
         if (strstr($meta['sale_price'], '%')) {
             update_post_meta($ID, 'sale_price', $sale_price);
         } else {
             if (!empty($sale_price) && $sale_price < fflcommerce_sanitize_num($meta['regular_price'])) {
                 update_post_meta($ID, 'sale_price', $sale_price);
             } else {
                 // silently fail if entered sale price > regular price (or nothing entered)
                 update_post_meta($ID, 'sale_price', '');
             }
         }
         update_post_meta($ID, 'weight', $meta['weight']);
         update_post_meta($ID, 'length', $meta['length']);
         update_post_meta($ID, 'height', $meta['height']);
         update_post_meta($ID, 'width', $meta['width']);
         update_post_meta($ID, 'stock', $meta['stock']);
         update_post_meta($ID, '_thumbnail_id', $meta['_thumbnail_id']);
         // Downloadable Only
         if ($meta['product-type'] == 'downloadable') {
             update_post_meta($ID, 'file_path', $meta['file_path']);
             update_post_meta($ID, 'download_limit', $meta['download_limit']);
         }
         // Remove the current data
         delete_post_meta($ID, 'variation_data');
         // Update taxonomies
         $variation_data = array();
         foreach ($attributes as $attribute) {
             // Skip if attribute is not for variation
             if (!isset($attribute['variation'])) {
                 continue;
             }
             // Configure the data
             $key = 'tax_' . sanitize_title($attribute['name']);
             if (isset($meta[$key])) {
                 $variation_data[$key] = $meta[$key];
             }
         }
         update_post_meta($ID, 'variation_data', $variation_data);
         do_action('fflcommerce_variable_product_table_data_save', $ID, $meta);
     }
     // Update default attribute options setting
     $default_attributes = array();
     foreach ($attributes as $attribute) {
         if (isset($attribute['variation'])) {
             $value = 'default_attribute_' . sanitize_title($attribute['name']);
             if (isset($_POST[$value])) {
                 $value = esc_attr(trim($_POST[$value]));
             } else {
                 $value = null;
             }
             if ($value) {
                 $default_attributes[sanitize_title($attribute['name'])] = $value;
             }
         }
     }
     update_post_meta($parent_id, '_default_attributes', $default_attributes);
     update_post_meta($parent_id, 'regular_price', $minimal_price);
 }
Esempio n. 23
0
/**
 * Product data box
 *
 * Displays the product data box, tabbed, with several panels covering price, stock etc
 *
 * @since 		1.0
 */
function fflcommerce_product_data_box()
{
    global $post, $wpdb, $thepostid;
    add_action('admin_footer', 'fflcommerce_meta_scripts');
    wp_nonce_field('fflcommerce_save_data', 'fflcommerce_meta_nonce');
    $thepostid = $post->ID;
    // Product Type
    $terms = get_the_terms($thepostid, 'product_type');
    $product_type = $terms ? current($terms)->slug : 'simple';
    $product_type_selector = apply_filters('fflcommerce_product_type_selector', array('simple' => __('Simple', 'fflcommerce'), 'downloadable' => __('Downloadable', 'fflcommerce'), 'grouped' => __('Grouped', 'fflcommerce'), 'virtual' => __('Virtual', 'fflcommerce'), 'variable' => __('Variable', 'fflcommerce'), 'external' => __('External / Affiliate', 'fflcommerce')));
    $product_type_select = '<div class="product-type-label">' . __('Product Type', 'fflcommerce') . '</div><select id="product-type" name="product-type"><optgroup label="' . __('Product Type', 'fflcommerce') . '">';
    foreach ($product_type_selector as $value => $label) {
        $product_type_select .= '<option value="' . $value . '" ' . selected($product_type, $value, false) . '>' . $label . '</option>';
    }
    $product_type_select .= '</optgroup></select><div class="clear"></div>';
    ?>

	<div class="panels">
		<span class="fflcommerce_product_data_type"><?php 
    echo $product_type_select;
    ?>
</span>
		<ul class="product_data_tabs tabs" style="display:none;">
			<li class="general_tab active">
				<a href="#general"><?php 
    _e('General', 'fflcommerce');
    ?>
</a>
			</li>

			<li class="advanced_tab">
				<a href="#tax"><?php 
    _e('Advanced', 'fflcommerce');
    ?>
</a>
			</li>

			<?php 
    if (FFLCommerce_Base::get_options()->get('fflcommerce_manage_stock') == 'yes') {
        ?>
			<li class="inventory_tab">
				<a href="#inventory"><?php 
        _e('Inventory', 'fflcommerce');
        ?>
</a>
			</li>
			<?php 
    }
    ?>

			<li class="attributes_tab">
				<a href="#attributes"><?php 
    _e('Attributes', 'fflcommerce');
    ?>
</a>
			</li>

			<li class="grouped_tab">
				<a href="#grouped"><?php 
    _e('Grouping', 'fflcommerce');
    ?>
</a>
			</li>

			<li class="file_tab">
				<a href="#files"><?php 
    _e('Download', 'fflcommerce');
    ?>
</a>
			</li>

			<?php 
    do_action('fflcommerce_product_write_panel_tabs');
    ?>
			<?php 
    do_action('product_write_panel_tabs');
    ?>
		</ul>

		<div id="general" class="panel fflcommerce_options_panel">
			<fieldset>
			<?php 
    // Visibility
    $args = array('id' => 'product_visibility', 'label' => __('Visibility', 'fflcommerce'), 'options' => array('visible' => __('Catalog & Search', 'fflcommerce'), 'catalog' => __('Catalog Only', 'fflcommerce'), 'search' => __('Search Only', 'fflcommerce'), 'hidden' => __('Hidden', 'fflcommerce')), 'selected' => get_post_meta($post->ID, 'visibility', true));
    echo FFLCommerce_Forms::select($args);
    // Featured
    $args = array('id' => 'featured', 'label' => __('Featured?', 'fflcommerce'), 'desc' => __('Enable this option to feature this product', 'fflcommerce'), 'value' => false);
    echo FFLCommerce_Forms::checkbox($args);
    ?>
			</fieldset>
			<fieldset>
			<?php 
    // SKU
    if (FFLCommerce_Base::get_options()->get('fflcommerce_enable_sku') !== 'no') {
        $args = array('id' => 'sku', 'label' => __('SKU', 'fflcommerce'), 'placeholder' => $post->ID);
        echo FFLCommerce_Forms::input($args);
    }
    //Brand
    if (FFLCommerce_Base::get_options()->get('fflcommerce_enable_brand') !== 'no') {
        $args = array('id' => 'brand', 'label' => __('Brand', 'fflcommerce'));
        echo FFLCommerce_Forms::input($args);
    }
    //GTIN
    if (FFLCommerce_Base::get_options()->get('fflcommerce_enable_gtin ') !== 'no') {
        $args = array('id' => 'gtin', 'label' => __('GTIN ', 'fflcommerce'));
        echo FFLCommerce_Forms::input($args);
    }
    //MPN
    if (FFLCommerce_Base::get_options()->get('fflcommerce_enable_mpn') !== 'no') {
        $args = array('id' => 'mpn', 'label' => __('MPN', 'fflcommerce'));
        echo FFLCommerce_Forms::input($args);
    }
    ?>
			</fieldset>

			<fieldset id="price_fieldset">
			<?php 
    // Regular Price
    $args = array('id' => 'regular_price', 'label' => __('Regular Price', 'fflcommerce'), 'after_label' => ' (' . get_fflcommerce_currency_symbol() . ')', 'type' => 'number', 'step' => 'any', 'placeholder' => __('Price Not Announced', 'fflcommerce'));
    echo FFLCommerce_Forms::input($args);
    // Sale Price
    $args = array('id' => 'sale_price', 'label' => __('Sale Price', 'fflcommerce'), 'after_label' => ' (' . get_fflcommerce_currency_symbol() . __(' or %', 'fflcommerce') . ')', 'desc' => '<a href="#" class="sale_schedule">' . __('Schedule', 'fflcommerce') . '</a>', 'placeholder' => __('15% or 19.99', 'fflcommerce'));
    echo FFLCommerce_Forms::input($args);
    // Sale Price date range
    // TODO: Convert this to a helper somehow?
    $field = array('id' => 'sale_price_dates', 'label' => __('On Sale Between', 'fflcommerce'));
    $sale_price_dates_from = get_post_meta($thepostid, 'sale_price_dates_from', true);
    $sale_price_dates_to = get_post_meta($thepostid, 'sale_price_dates_to', true);
    echo '<p class="form-field sale_price_dates_fields">' . __('Current time:', 'fflcommerce') . ' ' . current_time('Y-m-d H:i') . '</p>';
    echo '	<p class="form-field sale_price_dates_fields">
							<label for="' . esc_attr($field['id']) . '_from">' . $field['label'] . '</label>
							<input type="text" class="short date-pick" name="' . esc_attr($field['id']) . '_from" id="' . esc_attr($field['id']) . '_from" value="';
    if ($sale_price_dates_from) {
        echo date('Y-m-d H:i', $sale_price_dates_from);
    }
    echo '" placeholder="' . __('From', 'fflcommerce') . ' (' . date('Y-m-d H:i') . ')" maxlength="16" />
							<input type="text" class="short date-pick" name="' . esc_attr($field['id']) . '_to" id="' . esc_attr($field['id']) . '_to" value="';
    if ($sale_price_dates_to) {
        echo date('Y-m-d H:i', $sale_price_dates_to);
    }
    echo '" placeholder="' . __('To', 'fflcommerce') . ' (' . date('Y-m-d H:i') . ')" maxlength="16" />
							<a href="#" class="cancel_sale_schedule">' . __('Cancel', 'fflcommerce') . '</a>
						</p>';
    ?>
			<?php 
    do_action('fflcommerce_product_pricing_options');
    /* allow extensions like sales flash pro to add pricing options */
    ?>
			</fieldset>

			<fieldset>
			<?php 
    // External products
    $args = array('id' => 'external_url', 'label' => __('Product URL', 'fflcommerce'), 'placeholder' => __('The URL of the external product (eg. http://www.google.com)', 'fflcommerce'), 'extras' => array());
    echo FFLCommerce_Forms::input($args);
    ?>
			</fieldset>
			<?php 
    do_action('fflcommerce_product_general_panel');
    ?>
		</div>
		<div id="tax" class="panel fflcommerce_options_panel">
			<fieldset id="tax_fieldset">
				<?php 
    // Tax Status
    $status = get_post_meta($post->ID, 'tax_status', true);
    if (empty($status)) {
        $status = FFLCommerce_Base::get_options()->get('fflcommerce_tax_defaults_status', 'taxable');
    }
    $args = array('id' => 'tax_status', 'label' => __('Tax Status', 'fflcommerce'), 'options' => array('taxable' => __('Taxable', 'fflcommerce'), 'shipping' => __('Shipping', 'fflcommerce'), 'none' => __('None', 'fflcommerce')), 'selected' => $status);
    echo FFLCommerce_Forms::select($args);
    ?>
				<p class="form_field tax_classes_field">
					<label for="tax_classes"><?php 
    _e('Tax Classes', 'fflcommerce');
    ?>
</label>
            <span class="multiselect short">
            <?php 
    $_tax = new fflcommerce_tax();
    $tax_classes = $_tax->get_tax_classes();
    $selections = get_post_meta($post->ID, 'tax_classes', true);
    if (!is_array($selections)) {
        $selections = FFLCommerce_Base::get_options()->get('fflcommerce_tax_defaults_classes', array('*'));
    }
    $checked = checked(in_array('*', $selections), true, false);
    printf('<label %s><input type="checkbox" name="tax_classes[]" value="%s" %s/> %s</label>', !empty($checked) ? 'class="selected"' : '', '*', $checked, __('Standard', 'fflcommerce'));
    if ($tax_classes) {
        foreach ($tax_classes as $tax_class) {
            $checked = checked(in_array(sanitize_title($tax_class), $selections), true, false);
            printf('<label %s><input type="checkbox" name="tax_classes[]" value="%s" %s/> %s</label>', !empty($checked) ? 'class="selected"' : '', sanitize_title($tax_class), $checked, __($tax_class, 'fflcommerce'));
        }
    }
    ?>
            </span>
            <span class="multiselect-controls">
						<a class="check-all" href="#"><?php 
    _e('Check All', 'fflcommerce');
    ?>
</a>&nbsp;|
						<a class="uncheck-all" href="#"><?php 
    _e('Uncheck All', 'fflcommerce');
    ?>
</a>
					</span>
				</p>
			</fieldset>

			<?php 
    if (FFLCommerce_Base::get_options()->get('fflcommerce_enable_weight') !== 'no' || FFLCommerce_Base::get_options()->get('fflcommerce_enable_dimensions', true) !== 'no') {
        ?>
			<fieldset id="form_fieldset">
			<?php 
        // Weight
        if (FFLCommerce_Base::get_options()->get('fflcommerce_enable_weight') !== 'no') {
            $args = array('id' => 'weight', 'label' => __('Weight', 'fflcommerce'), 'after_label' => ' (' . FFLCommerce_Base::get_options()->get('fflcommerce_weight_unit') . ')', 'type' => 'number', 'step' => 'any', 'placeholder' => '0.00');
            echo FFLCommerce_Forms::input($args);
        }
        // Dimensions
        if (FFLCommerce_Base::get_options()->get('fflcommerce_enable_dimensions', true) !== 'no') {
            echo '
					<p class="form-field dimensions_field">
						<label for"product_length">' . __('Dimensions', 'fflcommerce') . ' (' . FFLCommerce_Base::get_options()->get('fflcommerce_dimension_unit') . ')' . '</label>
						<input type="number" step="any" name="length" class="short" value="' . get_post_meta($thepostid, 'length', true) . '" placeholder="' . __('Length', 'fflcommerce') . '" />
						<input type="number" step="any" name="width" class="short" value="' . get_post_meta($thepostid, 'width', true) . '" placeholder="' . __('Width', 'fflcommerce') . '" />
						<input type="number" step="any" name="height" class="short" value="' . get_post_meta($thepostid, 'height', true) . '" placeholder="' . __('Height', 'fflcommerce') . '" />
					</p>
					';
        }
        ?>
			</fieldset>
			<?php 
    }
    ?>

			<fieldset>
			<?php 
    // Customizable
    $args = array('id' => 'product_customize', 'label' => __('Can be personalized', 'fflcommerce'), 'options' => array('no' => __('No', 'fflcommerce'), 'yes' => __('Yes', 'fflcommerce')), 'selected' => get_post_meta($post->ID, 'customizable', true));
    echo FFLCommerce_Forms::select($args);
    // Customizable length
    $args = array('id' => 'customized_length', 'label' => __('Personalized Characters', 'fflcommerce'), 'type' => 'number', 'value' => get_post_meta($post->ID, 'customized_length', true), 'placeholder' => __('Leave blank for unlimited', 'fflcommerce'));
    echo FFLCommerce_Forms::input($args);
    ?>
			</fieldset>
			<?php 
    do_action('fflcommerce_product_tax_panel');
    ?>

		</div>

		<?php 
    if (FFLCommerce_Base::get_options()->get('fflcommerce_manage_stock') == 'yes') {
        ?>
		<div id="inventory" class="panel fflcommerce_options_panel">
			<fieldset>
			<?php 
        // manage stock
        $args = array('id' => 'manage_stock', 'label' => __('Manage Stock?', 'fflcommerce'), 'desc' => __('Handle stock for me', 'fflcommerce'), 'value' => false);
        echo FFLCommerce_Forms::checkbox($args);
        ?>
			</fieldset>
			<fieldset>
			<?php 
        // Stock Status
        // TODO: These values should be true/false
        $args = array('id' => 'stock_status', 'label' => __('Stock Status', 'fflcommerce'), 'options' => array('instock' => __('In Stock', 'fflcommerce'), 'outofstock' => __('Out of Stock', 'fflcommerce')));
        echo FFLCommerce_Forms::select($args);
        echo '<div class="stock_fields">';
        // Stock
        // TODO: Missing default value of 0
        $args = array('id' => 'stock', 'label' => __('Stock Quantity', 'fflcommerce'), 'type' => 'number');
        echo FFLCommerce_Forms::input($args);
        // Backorders
        $args = array('id' => 'backorders', 'label' => __('Allow Backorders?', 'fflcommerce'), 'options' => array('no' => __('Do not allow', 'fflcommerce'), 'notify' => __('Allow, but notify customer', 'fflcommerce'), 'yes' => __('Allow', 'fflcommerce')));
        echo FFLCommerce_Forms::select($args);
        echo '</div>';
        ?>
			</fieldset>
			<?php 
        do_action('fflcommerce_product_inventory_panel');
        ?>
		</div>
		<?php 
    }
    ?>

		<div id="attributes" class="panel">
			<?php 
    do_action('fflcommerce_attributes_display');
    ?>
		</div>

		<div id="grouped" class="panel fflcommerce_options_panel">
			<?php 
    // Grouped Products
    // TODO: Needs refactoring & a bit of love
    $posts_in = (array) get_objects_in_term(get_term_by('slug', 'grouped', 'product_type')->term_id, 'product_type');
    $posts_in = array_unique($posts_in);
    if ((bool) $posts_in) {
        $args = array('post_type' => 'product', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'asc', 'post_parent' => 0, 'include' => $posts_in);
        $grouped_products = get_posts($args);
        $options = array(null => '&ndash; Pick a Product Group &ndash;');
        if ($grouped_products) {
            foreach ($grouped_products as $product) {
                if ($product->ID == $post->ID) {
                    continue;
                }
                $options[$product->ID] = $product->post_title;
            }
        }
        // Only echo the form if we have grouped products
        $args = array('id' => 'parent_id', 'label' => __('Product Group', 'fflcommerce'), 'options' => $options, 'selected' => $post->post_parent);
        echo FFLCommerce_Forms::select($args);
    }
    // Ordering
    $args = array('id' => 'menu_order', 'label' => __('Sort Order', 'fflcommerce'), 'type' => 'number', 'value' => $post->menu_order);
    echo FFLCommerce_Forms::input($args);
    $args = array('id' => 'variation_order', 'label' => __('Variation Order', 'fflcommerce'), 'options' => array('asort' => __('By name ascending', 'fflcommerce'), 'arsort' => __('By name descending', 'fflcommerce'), 'ksort' => __('From first to last key', 'fflcommerce'), 'krsort' => __('From last to first key', 'fflcommerce'), 'shuffle' => __('Random', 'fflcommerce')), 'selected' => get_post_meta($post->ID, 'variation_order', true));
    echo FFLCommerce_Forms::select($args);
    ?>
			<?php 
    do_action('fflcommerce_product_grouped_panel');
    ?>
		</div>

		<div id="files" class="panel fflcommerce_options_panel">
			<fieldset>
			<?php 
    // DOWNLOADABLE OPTIONS
    // File URL
    // TODO: Refactor this into a helper
    $file_path = get_post_meta($post->ID, 'file_path', true);
    $field = array('id' => 'file_path', 'label' => __('File Path', 'fflcommerce'));
    echo '<p class="form-field"><label for="' . esc_attr($field['id']) . '">' . $field['label'] . ':</label>
				<input type="text" class="file_path" name="' . esc_attr($field['id']) . '" id="' . esc_attr($field['id']) . '" value="' . esc_attr($file_path) . '" placeholder="' . site_url() . '" />
				<input type="button"  class="upload_file_button button" data-postid="' . esc_attr($post->ID) . '" value="' . __('Upload a file', 'fflcommerce') . '" />
			</p>';
    // Download Limit
    $args = array('id' => 'download_limit', 'label' => __('Download Limit', 'fflcommerce'), 'type' => 'number', 'desc' => __('Leave blank for unlimited re-downloads', 'fflcommerce'));
    echo FFLCommerce_Forms::input($args);
    do_action('additional_downloadable_product_type_options');
    ?>
			</fieldset>
			<?php 
    do_action('fflcommerce_product_files_panel');
    ?>
		</div>

		<?php 
    do_action('fflcommerce_product_write_panels');
    ?>
		<?php 
    do_action('product_write_panels');
    ?>
	</div>
	<?php 
}
/**
 * Enqueue scripts
 * Enqueue JavaScript used by the meta panels.
 *
 * @since    1.0
 */
function fflcommerce_write_panel_scripts()
{
    $options = FFLCommerce_Base::get_options();
    $post_type = fflcommerce_get_current_post_type();
    if ($post_type !== 'product' && $post_type !== 'shop_order' && $post_type !== 'shop_coupon' && $post_type !== 'shop_email') {
        return;
    }
    wp_enqueue_script('jquery-ui-datepicker');
    jrto_enqueue_script('admin', 'fflcommerce_datetimepicker', FFLCOMMERCE_URL . '/assets/js/jquery-ui-timepicker-addon.min.js', array('jquery', 'jquery-ui-datepicker'));
    jrto_enqueue_script('admin', 'fflcommerce-select2', FFLCOMMERCE_URL . '/assets/js/select2.min.js', array('jquery'));
    jrto_enqueue_script('admin', 'fflcommerce-writepanel', FFLCOMMERCE_URL . '/assets/js/write-panels.js', array('jquery', 'fflcommerce-select2'));
    jrto_enqueue_script('admin', 'fflcommerce-bootstrap-tooltip', FFLCOMMERCE_URL . '/assets/js/bootstrap-tooltip.min.js', array('jquery'), array('version' => '2.0.3'));
    wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
    wp_enqueue_style('thickbox');
    $params = array('remove_item_notice' => __("Remove this item? If you have previously reduced this item's stock, or this order was submitted by a customer, will need to manually restore the item's stock.", 'fflcommerce'), 'cart_total' => __('Calc totals based on order items and taxes?', 'fflcommerce'), 'copy_billing' => __('Copy billing information to shipping information? This will remove any currently entered shipping information.', 'fflcommerce'), 'prices_include_tax' => $options->get('fflcommerce_prices_include_tax'), 'ID' => __('ID', 'fflcommerce'), 'item_name' => __('Item Name', 'fflcommerce'), 'quantity' => __('Quantity e.g. 2', 'fflcommerce'), 'cost_unit' => __('Cost per unit e.g. 2.99', 'fflcommerce'), 'tax_rate' => __('Tax Rate e.g. 20.0000', 'fflcommerce'), 'meta_name' => __('Meta Name', 'fflcommerce'), 'meta_value' => __('Meta Value', 'fflcommerce'), 'custom_attr_heading' => __('Custom Attribute', 'fflcommerce'), 'display_attr_label' => __('Display on product page', 'fflcommerce'), 'variation_attr_label' => __('Is for variations', 'fflcommerce'), 'confirm_remove_attr' => __('Remove this attribute?', 'fflcommerce'), 'assets_url' => FFLCOMMERCE_URL, 'ajax_url' => admin_url('admin-ajax.php'), 'add_order_item_nonce' => wp_create_nonce('add-order-item'));
    jrto_localize_script('fflcommerce-writepanel', 'fflcommerce_params', $params);
}
Esempio n. 25
0
function fflcommerce_view_order()
{
    $options = FFLCommerce_Base::get_options();
    $order = new fflcommerce_order($_GET['order']);
    fflcommerce_render('shortcode/my_account/view_order', array('order' => $order, 'options' => $options));
}
    function format_tax_rates_for_display($value)
    {
        $_tax = new fflcommerce_tax();
        $tax_classes = $_tax->get_tax_classes();
        $tax_rates = FFLCommerce_Base::get_options()->get('fflcommerce_tax_rates');
        if (empty($tax_rates)) {
            $tax_rates = array();
        }
        $applied_all_states = array();
        ob_start();
        ?>
		<div id="fflcommerce_tax_rates">
			<table class="tax_rate_rules" cellspacing="0">
				<thead>
					<tr>
						<th><?php 
        _e('Remove', 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e('Tax Classes', 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e('Online Label', 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e('Country/State', 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e("Rate (%)", 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e('Apply to shipping', 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e('Compound', 'fflcommerce');
        ?>
</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<th><?php 
        _e('Remove', 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e('Tax Classes', 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e('Online Label', 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e('Country/State', 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e("Rate (%)", 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e('Apply to shipping', 'fflcommerce');
        ?>
</th>
						<th><?php 
        _e('Compound', 'fflcommerce');
        ?>
</th>
					</tr>
				</tfoot>
				<tbody>
					<?php 
        $i = -1;
        if ($tax_rates && is_array($tax_rates) && sizeof($tax_rates) > 0) {
            $tax_rates = $this->array_compare($tax_rates);
            foreach ($tax_rates as $rate) {
                if (isset($rate['is_all_states']) && in_array($rate['country'] . $rate['class'], $applied_all_states)) {
                    continue;
                }
                $i++;
                // increment counter after check for all states having been applied
                echo '<tr class="tax_rate"><td><a href="#" class="remove button">&times;</a></td>';
                echo '<td><select id="tax_classes[' . esc_attr($i) . ']" name="tax_classes[' . esc_attr($i) . ']"><option value="*">' . __('Standard Rate', 'fflcommerce') . '</option>';
                if ($tax_classes) {
                    foreach ($tax_classes as $class) {
                        echo '<option value="' . sanitize_title($class) . '"';
                        if (isset($rate['class']) && $rate['class'] == sanitize_title($class)) {
                            echo 'selected="selected"';
                        }
                        echo '>' . $class . '</option>';
                    }
                }
                echo '</select></td>';
                echo '<td><input type="text" value="' . esc_attr($rate['label']) . '" name="tax_label[' . esc_attr($i) . ']" placeholder="' . __('Online Label', 'fflcommerce') . '" size="10" /></td>';
                echo '<td><select name="tax_country[' . esc_attr($i) . '][]" id="tax_country_' . esc_attr($i) . '" class="tax_select2" multiple="multiple" style="width:220px;">';
                if (isset($rate['is_all_states'])) {
                    if (is_array($applied_all_states) && !in_array($rate['country'] . $rate['class'], $applied_all_states)) {
                        $applied_all_states[] = $rate['country'] . $rate['class'];
                        fflcommerce_countries::country_dropdown_options($rate['country'], '*', true);
                        //all-states
                    } else {
                        continue;
                    }
                } else {
                    fflcommerce_countries::country_dropdown_options($rate['country'], $rate['state'], true);
                }
                echo '</select>';
                echo '<button class="select_none button">' . __('None', 'fflcommerce') . '</button><button class="button select_all">' . __('All', 'fflcommerce') . '</button><button class="button select_us_states">' . __('US States', 'fflcommerce') . '</button><button class="button select_europe">' . __('EU States', 'fflcommerce') . '</button></td>';
                echo '<td><input type="text" value="' . esc_attr($rate['rate']) . '" name="tax_rate[' . esc_attr($i) . ']" placeholder="' . __('Rate (%)', 'fflcommerce') . '" size="6" /></td>';
                echo '<td><input type="checkbox" name="tax_shipping[' . esc_attr($i) . ']" ';
                if (isset($rate['shipping']) && $rate['shipping'] == 'yes') {
                    echo 'checked="checked"';
                }
                echo ' /></td>';
                echo '<td><input type="checkbox" name="tax_compound[' . esc_attr($i) . ']" ';
                if (isset($rate['compound']) && $rate['compound'] == 'yes') {
                    echo 'checked="checked"';
                }
                echo ' /></td></tr>';
                ?>
<script type="text/javascript">
							/*<![CDATA[*/
								jQuery(function() {
									jQuery("#tax_country_<?php 
                echo esc_attr($i);
                ?>
").select2();
								});
							/*]]>*/
							</script><?php 
            }
        }
        ?>
				</tbody>

			</table>
			<div><a href="#" class="add button"><?php 
        _e('+ Add Tax Rule', 'fflcommerce');
        ?>
</a></div>
		</div>

		<script type="text/javascript">
		/*<![CDATA[*/
			jQuery(function() {

				jQuery(document.body).on('click', 'tr.tax_rate .select_none', function(){
					jQuery(this).closest('td').find('select option').removeAttr("selected");
					jQuery(this).closest('td').find('select.tax_select2').trigger("change");
					return false;
				});
				jQuery(document.body).on('click', 'tr.tax_rate .select_all', function(){
					jQuery(this).closest('td').find('select option').attr("selected","selected");
					jQuery(this).closest('td').find('select.tax_select2').trigger("change");
					return false;
				});
				jQuery(document.body).on('click', 'tr.tax_rate .select_us_states', function(){
					jQuery(this).closest('td').find('select optgroup[label="<?php 
        _e('United States', 'fflcommerce');
        ?>
"] option').attr("selected","selected");
					jQuery(this).closest('td').find('select.tax_select2').trigger("change");
					return false;
				});
				jQuery(document.body).on('change', 'tr.tax_rate .options select', function(e){
					jQuery(this).trigger("liszt:updated");
					jQuery(this).closest('td').find('label').text( jQuery(":selected", this).length + ' ' + '<?php 
        _e('countries/states selected', 'fflcommerce');
        ?>
' );
				});
				jQuery(document.body).on('click', 'tr.tax_rate .select_europe', function(e){
					jQuery(this).closest('td').find('option[value="BE"],option[value="FR"],option[value="DE"],option[value="IT"],option[value="LU"],option[value="NL"],option[value="DK"],option[value="IE"],option[value="GR"],option[value="PT"],option[value="ES"],option[value="AT"],option[value="FI"],option[value="SE"],option[value="CY"],option[value="CZ"],option[value="EE"],option[value="HU"],option[value="LV"],option[value="LT"],option[value="MT"],option[value="PL"],option[value="SK"],option[value="SI"],option[value="RO"],option[value="BG"],option[value="IM"],option[value="GB"]').attr("selected","selected");
					jQuery(this).closest('td').find('select.tax_select2').trigger("change");
					return false;
				});

				jQuery(document.body).on('click', '#fflcommerce_tax_rates a.add', function() {
					var size = jQuery('.tax_rate_rules tbody tr').size();
					jQuery('<tr class="tax_rate"> \
							<td><a href="#" class="remove button">&times;</a></td> \
							<td><select name="tax_classes[' + size + ']" > \
								<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></td> \
							<td><input type="text" name="tax_label[' + size + ']" placeholder="<?php 
        _e('Online Label', 'fflcommerce');
        ?>
" size="10" /></td> \
							<td><select name="tax_country[' + size + '][]" id="tax_country_' + size +'" multiple="multiple" style="width:220px;"> \
									<?php 
        fflcommerce_countries::country_dropdown_options('', '', true);
        ?>
</select> \
								<button class="select_none button"><?php 
        _e('None', 'fflcommerce');
        ?>
</button> \
								<button class="button select_all"><?php 
        _e('All', 'fflcommerce');
        ?>
</button> \
								<button class="button select_us_states"><?php 
        _e('US States', 'fflcommerce');
        ?>
</button> \
								<button class="button select_europe"><?php 
        _e('EU States', 'fflcommerce');
        ?>
</button></td> \
							<td><input type="text" name="tax_rate[' + size + ']" placeholder="<?php 
        _e('Rate (%)', 'fflcommerce');
        ?>
" size="6" /> \
							<td><input type="checkbox" name="tax_shipping[' + size + ']" /></td> \
							<td><input type="checkbox" name="tax_compound[' + size + ']" /></td> \
							</tr>'
					).appendTo('#fflcommerce_tax_rates .tax_rate_rules tbody');
					jQuery('#tax_country_' + size).select2();
					jQuery('#tax_country_' + size).addClass("tax_select2");
					return false;
				});
				jQuery(document.body).on('click', '#fflcommerce_tax_rates a.remove', function(){
					var answer = confirm("<?php 
        _e('Delete this rule?', 'fflcommerce');
        ?>
");
					if (answer) jQuery(this).parent().parent().remove();
					return false;
				});
			});
			/*]]>*/
			</script>
		<?php 
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }
 function fflcommerce_breadcrumb($delimiter = ' &rsaquo; ', $wrap_before = '<div id="breadcrumb">', $wrap_after = '</div>', $before = '', $after = '', $home = null)
 {
     global $post, $wp_query, $author;
     $options = FFLCommerce_Base::get_options();
     if (!$home) {
         $home = _x('Home', 'breadcrumb', 'fflcommerce');
     }
     $home_link = home_url();
     $prepend = '';
     if ($options->get('fflcommerce_prepend_shop_page_to_urls') == "yes" && fflcommerce_get_page_id('shop') && get_option('page_on_front') !== fflcommerce_get_page_id('shop')) {
         $prepend = $before . '<a href="' . esc_url(fflcommerce_cart::get_shop_url()) . '">' . get_the_title(fflcommerce_get_page_id('shop')) . '</a> ' . $after . $delimiter;
     }
     if (!is_home() && !is_front_page() && !(is_post_type_archive() && get_option('page_on_front') == fflcommerce_get_page_id('shop')) || is_paged()) {
         echo $wrap_before;
         echo $before . '<a class="home" href="' . $home_link . '">' . $home . '</a> ' . $after . $delimiter;
         if (is_category()) {
             $cat_obj = $wp_query->get_queried_object();
             $this_category = $cat_obj->term_id;
             $this_category = get_category($this_category);
             if ($this_category->parent != 0) {
                 $parent_category = get_category($this_category->parent);
                 echo get_category_parents($parent_category->term_id, true, $delimiter);
             }
             echo $before . single_cat_title('', false) . $after;
         } elseif (is_tax('product_cat')) {
             $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
             $parents = array();
             $parent = $term->parent;
             while ($parent) {
                 $parents[] = $parent;
                 $new_parent = get_term_by('id', $parent, get_query_var('taxonomy'));
                 $parent = $new_parent->parent;
             }
             if (!empty($parents)) {
                 $parents = array_reverse($parents);
                 foreach ($parents as $parent) {
                     $item = get_term_by('id', $parent, get_query_var('taxonomy'));
                     echo $before . '<a href="' . get_term_link($item->slug, 'product_cat') . '">' . $item->name . '</a>' . $after . $delimiter;
                 }
             }
             $queried_object = $wp_query->get_queried_object();
             echo $prepend . $before . $queried_object->name . $after;
         } elseif (is_tax('product_tag')) {
             $queried_object = $wp_query->get_queried_object();
             echo $prepend . $before . __('Products tagged &ldquo;', 'fflcommerce') . $queried_object->name . '&rdquo;' . $after;
         } elseif (is_day()) {
             echo $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $after . $delimiter;
             echo $before . '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $after . $delimiter;
             echo $before . get_the_time('d') . $after;
         } elseif (is_month()) {
             echo $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $after . $delimiter;
             echo $before . get_the_time('F') . $after;
         } elseif (is_year()) {
             echo $before . get_the_time('Y') . $after;
         } elseif (is_post_type_archive('product') && get_option('page_on_front') !== fflcommerce_get_page_id('shop')) {
             $_name = fflcommerce_get_page_id('shop') ? get_the_title(fflcommerce_get_page_id('shop')) : ucwords($options->get('fflcommerce_shop_slug'));
             if (is_search()) {
                 echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $delimiter . __('Search results for &ldquo;', 'fflcommerce') . get_search_query() . '&rdquo;' . $after;
             } else {
                 echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $after;
             }
         } elseif (is_single() && !is_attachment()) {
             if (get_post_type() == 'product') {
                 echo $prepend;
                 if ($terms = get_the_terms($post->ID, 'product_cat')) {
                     $term = apply_filters('fflcommerce_product_cat_breadcrumb_terms', current($terms), $terms);
                     $parents = array();
                     $parent = $term->parent;
                     while ($parent) {
                         $parents[] = $parent;
                         $new_parent = get_term_by('id', $parent, 'product_cat');
                         $parent = $new_parent->parent;
                     }
                     if (!empty($parents)) {
                         $parents = array_reverse($parents);
                         foreach ($parents as $parent) {
                             $item = get_term_by('id', $parent, 'product_cat');
                             echo $before . '<a href="' . get_term_link($item->slug, 'product_cat') . '">' . $item->name . '</a>' . $after . $delimiter;
                         }
                     }
                     echo $before . '<a href="' . get_term_link($term->slug, 'product_cat') . '">' . $term->name . '</a>' . $after . $delimiter;
                 }
                 echo $before . get_the_title() . $after;
             } elseif (get_post_type() != 'post') {
                 $post_type = get_post_type_object(get_post_type());
                 echo $before . '<a href="' . get_post_type_archive_link(get_post_type()) . '">' . $post_type->labels->singular_name . '</a>' . $after . $delimiter;
                 echo $before . get_the_title() . $after;
             } else {
                 $cat = current(get_the_category());
                 echo get_category_parents($cat, true, $delimiter);
                 echo $before . get_the_title() . $after;
             }
         } elseif (is_404()) {
             echo $before . __('Error 404', 'fflcommerce') . $after;
         } elseif (!is_single() && !is_page() && get_post_type() != 'post') {
             $post_type = get_post_type_object(get_post_type());
             if ($post_type) {
                 echo $before . $post_type->labels->singular_name . $after;
             }
         } elseif (is_attachment()) {
             $parent = get_post($post->post_parent);
             $cat = get_the_category($parent->ID);
             $cat = $cat[0];
             echo get_category_parents($cat, true, '' . $delimiter);
             echo $before . '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>' . $after . $delimiter;
             echo $before . get_the_title() . $after;
         } elseif (is_page() && !$post->post_parent) {
             echo $before . get_the_title() . $after;
         } elseif (is_page() && $post->post_parent) {
             $parent_id = $post->post_parent;
             $breadcrumbs = array();
             while ($parent_id) {
                 $page = get_post($parent_id);
                 $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
                 $parent_id = $page->post_parent;
             }
             $breadcrumbs = array_reverse($breadcrumbs);
             foreach ($breadcrumbs as $crumb) {
                 echo $crumb . '' . $delimiter;
             }
             echo $before . get_the_title() . $after;
         } elseif (is_search()) {
             echo $before . __('Search results for &ldquo;', 'fflcommerce') . get_search_query() . '&rdquo;' . $after;
         } elseif (is_tag()) {
             echo $before . __('Posts tagged &ldquo;', 'fflcommerce') . single_tag_title('', false) . '&rdquo;' . $after;
         } elseif (is_author()) {
             $userdata = get_userdata($author);
             echo $before . __('Author: ', 'fflcommerce') . $userdata->display_name . $after;
         }
         if (get_query_var('paged')) {
             echo ' (' . __('Page', 'fflcommerce') . ' ' . get_query_var('paged') . ')';
         }
         echo $wrap_after;
     }
 }
Esempio n. 28
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);
    }
}
Esempio n. 29
0
 * Do not edit or add directly to this file if you wish to upgrade FFL Commerce to newer
 * versions in the future. If you wish to customise FFL Commerce core for your needs,
 * please use our GitHub repository to publish essential changes for consideration.
 *
 * @package             FFLCommerce
 * @category            Checkout
 * @author              Tampa Bay Tactical Supply, Inc.
 * @copyright           Copyright © 2011-2014 Tampa Bay Tactical Supply, Inc. & Jigoshop.
 * @license             GNU General Public License v3
 * 
 */
?>

<?php 
global $order;
$options = FFLCommerce_Base::get_options();
?>
<form id="pay_for_order" method="post">
    <table class="shop_table">
        <thead>
            <tr>
                <th><?php 
_e('Product', 'fflcommerce');
?>
</th>
                <th><?php 
_e('Qty', 'fflcommerce');
?>
</th>
                <th><?php 
_e('Totals', 'fflcommerce');
/**
 * Properly sets the WP Nav Menus items classes for FFL Commerce queried objects
 *
 * @param $menu_items
 * @param array $args
 * @return
 * @TODO set parent items classes when the shop page is not at the nav menu root
 */
function fflcommerce_nav_menu_items_classes($menu_items, $args)
{
    $options = FFLCommerce_Base::get_options();
    $shop_page_id = (int) fflcommerce_get_page_id('shop');
    // only add nav menu classes if the queried object is the Shop page or derivative (Product, Category, Tag)
    if (empty($shop_page_id) || !is_content_wrapped()) {
        return $menu_items;
    }
    $home_page_id = (int) $options->get('page_for_posts');
    foreach ((array) $menu_items as $key => $menu_item) {
        $classes = (array) $menu_item->classes;
        // unset classes set by WP on the home page item
        // shouldn't need a content wrap check as we can't get here without it  -JAP-
        if (is_content_wrapped() && $home_page_id == $menu_item->object_id) {
            $menu_items[$key]->current = false;
            unset($classes[array_search('current_page_parent', $classes)]);
            unset($classes[array_search('current-menu-item', $classes)]);
        }
        if (is_shop() && $shop_page_id == $menu_item->object_id) {
            // is products archive
            $menu_items[$key]->current = true;
            $classes[] = 'current-menu-item';
            $classes[] = 'current_page_item';
        } elseif ((is_product() || is_product_category() || is_product_tag()) && $shop_page_id == $menu_item->object_id) {
            // is another fflcommerce object
            $classes[] = 'current_page_parent';
            $classes[] = 'current_menu_parent';
        }
        $menu_items[$key]->classes = array_unique($classes);
    }
    return $menu_items;
}