Ejemplo n.º 1
0
    public function column_default($item, $column_name)
    {
        global $product;
        if (!$product || $product->id !== $item->id) {
            $product = new fflcommerce_product($item->id);
        }
        switch ($column_name) {
            case 'product':
                if ($sku = $product->get_sku()) {
                    echo $sku . ' - ';
                }
                echo $product->get_title();
                // Get variation data
                if ($product->is_type('variation')) {
                    $list_attributes = array();
                    $attributes = $product->get_available_attributes_variations();
                    foreach ($attributes as $name => $attribute) {
                        $list_attributes[] = $product->attribute_label(str_replace('pa_', '', $name)) . ': <strong>' . $attribute . '</strong>';
                    }
                    echo '<div class="description">' . implode(', ', $list_attributes) . '</div>';
                }
                break;
            case 'parent':
                if ($item->parent) {
                    echo get_the_title($item->parent);
                } else {
                    echo '-';
                }
                break;
            case 'stock_status':
                if ($product->is_in_stock() || !isset($product->meta['stock_manage']) && !isset($product->meta['stock_status']) && $product->get_stock() > 0) {
                    echo '<mark class="instock">' . __('In stock', 'fflcommerce') . '</mark>';
                } else {
                    echo '<mark class="outofstock">' . __('Out of stock', 'fflcommerce') . '</mark>';
                }
                break;
            case 'stock_level':
                echo $product->get_stock();
                break;
            case 'actions':
                ?>
<p>
				<?php 
                $actions = array();
                $action_id = $item->parent != 0 ? $item->parent : $item->id;
                $actions['edit'] = array('url' => admin_url('post.php?post=' . $action_id . '&action=edit'), 'name' => __('Edit', 'fflcommerce'), 'action' => "edit");
                if ($product->is_visible()) {
                    $actions['view'] = array('url' => get_permalink($action_id), 'name' => __('View', 'fflcommerce'), 'action' => "view");
                }
                $actions = apply_filters('fflcommerce_admin_stock_report_product_actions', $actions, $product);
                foreach ($actions as $action) {
                    printf('<a class="button tips %s" href="%s" data-tip="%s ' . __('product', 'fflcommerce') . '">%s</a>', $action['action'], esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name']));
                }
                ?>
				</p><?php 
                break;
        }
    }
Ejemplo n.º 2
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)
 {
     // Start buffering
     ob_start();
     extract($args);
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Random Products', 'fflcommerce'), $instance, $this->id_base);
     // Set number of products to fetch
     if (!($number = absint($instance['number']))) {
         $number = 5;
     }
     // Set up query
     $query_args = array('posts_per_page' => $number, 'post_type' => 'product', 'post_status' => 'publish', 'orderby' => 'rand', 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
     // Run the query
     $q = new WP_Query($query_args);
     // If there are products
     if ($q->have_posts()) {
         // Print the widget wrapper & title
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         // Open the list
         echo '<ul class="product_list_widget">';
         // Print out each product
         while ($q->have_posts()) {
             $q->the_post();
             // Get new fflcommerce_product instance
             $_product = new fflcommerce_product(get_the_ID());
             echo '<li>';
             // Print the product image & title with a link to the permalink
             echo '<a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '">';
             echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : fflcommerce_get_image_placeholder('shop_tiny');
             echo '<span class="js_widget_product_title">' . get_the_title() . '</span>';
             echo '</a>';
             // Print the price with html wrappers
             echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>';
             echo '</li>';
         }
         echo '</ul>';
         // Close the list
         // Print closing widget wrapper
         echo $after_widget;
         // Reset the global $the_post as this query will have stomped on it
         wp_reset_postdata();
     }
     ob_get_flush();
 }
Ejemplo n.º 3
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)
 {
     // Get the best selling products from the transient
     $cache = get_transient('fflcommerce_widget_cache');
     // If cached get from the cache
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return false;
     }
     // Start buffering
     ob_start();
     extract($args);
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Best Sellers', 'fflcommerce'), $instance, $this->id_base);
     // Set number of products to fetch
     if (!($number = absint($instance['number']))) {
         $number = 5;
     }
     // Set up query
     $query_args = array('posts_per_page' => $number, 'post_type' => 'product', 'post_status' => 'publish', 'meta_key' => 'quantity_sold', 'orderby' => 'meta_value_num+0', 'order' => 'desc', 'nopaging' => false, 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
     // Run the query
     $q = new WP_Query($query_args);
     // If there are products
     if ($q->have_posts()) {
         // Print the widget wrapper & title
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         // Open the list
         echo '<ul class="product_list_widget">';
         // Print out each product
         while ($q->have_posts()) {
             $q->the_post();
             // Get a new fflcommerce_product instance
             $_product = new fflcommerce_product(get_the_ID());
             echo '<li>';
             // Print the product image & title with a link to the permalink
             echo '<a href="' . esc_attr(get_permalink()) . '" title="' . esc_attr(get_the_title()) . '">';
             // Print the product image
             echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : fflcommerce_get_image_placeholder('shop_tiny');
             echo '<span class="js_widget_product_title">' . get_the_title() . '</span>';
             echo '</a>';
             // Print the price with html wrappers
             echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>';
             echo '</li>';
         }
         echo '</ul>';
         // Close the list
         // Print closing widget wrapper
         echo $after_widget;
         // Reset the global $the_post as this query will have stomped on it
         wp_reset_postdata();
     }
     // Flush output buffer and save to transient cache
     $cache[$args['widget_id']] = ob_get_flush();
     set_transient('fflcommerce_widget_cache', $cache, 3600 * 3);
     // 3 hours ahead
 }
Ejemplo n.º 4
0
/**
 * Custom Post Types
 **/
function fflcommerce_post_type()
{
    $options = FFLCommerce_Base::get_options();
    $shop_page_id = fflcommerce_get_page_id('shop');
    $base_slug = $shop_page_id && ($base_page = get_post($shop_page_id)) ? get_page_uri($shop_page_id) : 'shop';
    $category_base = $options->get('fflcommerce_prepend_shop_page_to_urls') == 'yes' ? trailingslashit($base_slug) : '';
    $category_slug = $options->get('fflcommerce_product_category_slug') ? $options->get('fflcommerce_product_category_slug') : _x('product-category', 'slug', 'fflcommerce');
    $tag_slug = $options->get('fflcommerce_product_tag_slug') ? $options->get('fflcommerce_product_tag_slug') : _x('product-tag', 'slug', 'fflcommerce');
    $product_base = $options->get('fflcommerce_prepend_shop_page_to_product') == 'yes' ? trailingslashit($base_slug) : trailingslashit(_x('product', 'slug', 'fflcommerce'));
    if ($options->get('fflcommerce_prepend_shop_page_to_product') == 'yes' && $options->get('fflcommerce_prepend_shop_page_to_urls') == 'yes') {
        $product_base .= trailingslashit(_x('product', 'slug', 'fflcommerce'));
    }
    if ($options->get('fflcommerce_prepend_category_to_product') == 'yes') {
        $product_base .= trailingslashit('%product_cat%');
    }
    $product_base = untrailingslashit($product_base);
    register_post_type("product", array('labels' => array('name' => __('Products', 'fflcommerce'), 'singular_name' => __('Product', 'fflcommerce'), 'all_items' => __('All Products', 'fflcommerce'), 'add_new' => __('Add New', 'fflcommerce'), 'add_new_item' => __('Add New Product', 'fflcommerce'), 'edit' => __('Edit', 'fflcommerce'), 'edit_item' => __('Edit Product', 'fflcommerce'), 'new_item' => __('New Product', 'fflcommerce'), 'view' => __('View Product', 'fflcommerce'), 'view_item' => __('View Product', 'fflcommerce'), 'search_items' => __('Search Products', 'fflcommerce'), 'not_found' => __('No Products found', 'fflcommerce'), 'not_found_in_trash' => __('No Products found in trash', 'fflcommerce'), 'parent' => __('Parent Product', 'fflcommerce')), 'description' => __('This is where you can add new products to your store.', 'fflcommerce'), 'public' => true, 'show_ui' => true, 'capability_type' => 'product', 'map_meta_cap' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'hierarchical' => false, 'rewrite' => array('slug' => $product_base, 'with_front' => false, 'feeds' => $base_slug), 'query_var' => true, 'supports' => array('title', 'editor', 'thumbnail', 'comments', 'excerpt'), 'has_archive' => $base_slug, 'show_in_nav_menus' => false, 'menu_position' => 56, 'menu_icon' => 'dashicons-book'));
    register_post_type("product_variation", array('labels' => array('name' => __('Variations', 'fflcommerce'), 'singular_name' => __('Variation', 'fflcommerce'), 'add_new' => __('Add Variation', 'fflcommerce'), 'add_new_item' => __('Add New Variation', 'fflcommerce'), 'edit' => __('Edit', 'fflcommerce'), 'edit_item' => __('Edit Variation', 'fflcommerce'), 'new_item' => __('New Variation', 'fflcommerce'), 'view' => __('View Variation', 'fflcommerce'), 'view_item' => __('View Variation', 'fflcommerce'), 'search_items' => __('Search Variations', 'fflcommerce'), 'not_found' => __('No Variations found', 'fflcommerce'), 'not_found_in_trash' => __('No Variations found in trash', 'fflcommerce'), 'parent' => __('Parent Variation', 'fflcommerce')), 'public' => false, 'show_ui' => false, 'publicly_queryable' => true, 'exclude_from_search' => true, 'show_in_nav_menus' => false, 'capability_type' => 'product', 'map_meta_cap' => true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('title', 'editor', 'custom-fields'), 'show_in_menu' => 'edit.php?post_type=product'));
    register_taxonomy('product_type', array('product'), array('hierarchical' => false, 'show_ui' => false, 'query_var' => true, 'show_in_nav_menus' => false));
    register_taxonomy('product_cat', array('product'), array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'labels' => array('menu_name' => __('Categories', 'fflcommerce'), 'name' => __('Product Categories', 'fflcommerce'), 'singular_name' => __('Product Category', 'fflcommerce'), 'search_items' => __('Search Product Categories', 'fflcommerce'), 'all_items' => __('All Product Categories', 'fflcommerce'), 'parent_item' => __('Parent Product Category', 'fflcommerce'), 'parent_item_colon' => __('Parent Product Category:', 'fflcommerce'), 'edit_item' => __('Edit Product Category', 'fflcommerce'), 'update_item' => __('Update Product Category', 'fflcommerce'), 'add_new_item' => __('Add New Product Category', 'fflcommerce'), 'new_item_name' => __('New Product Category Name', 'fflcommerce')), 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => $category_base . $category_slug, 'with_front' => false, 'hierarchical' => false)));
    register_taxonomy_for_object_type('product_cat', 'product');
    register_taxonomy('product_tag', array('product'), array('hierarchical' => false, 'labels' => array('menu_name' => __('Tags', 'fflcommerce'), 'name' => __('Product Tags', 'fflcommerce'), 'singular_name' => __('Product Tag', 'fflcommerce'), 'search_items' => __('Search Product Tags', 'fflcommerce'), 'all_items' => __('All Product Tags', 'fflcommerce'), 'parent_item' => __('Parent Product Tag', 'fflcommerce'), 'parent_item_colon' => __('Parent Product Tag:', 'fflcommerce'), 'edit_item' => __('Edit Product Tag', 'fflcommerce'), 'update_item' => __('Update Product Tag', 'fflcommerce'), 'add_new_item' => __('Add New Product Tag', 'fflcommerce'), 'new_item_name' => __('New Product Tag Name', 'fflcommerce')), 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => $category_base . $tag_slug, 'with_front' => false)));
    register_taxonomy_for_object_type('product_tag', 'product');
    $attribute_taxonomies = fflcommerce_product::getAttributeTaxonomies();
    if ($attribute_taxonomies) {
        foreach ($attribute_taxonomies as $tax) {
            $name = 'pa_' . sanitize_title($tax->attribute_name);
            $hierarchical = true;
            if ($name) {
                register_taxonomy($name, array('product'), array('hierarchical' => $hierarchical, 'labels' => array('name' => $tax->attribute_name, 'singular_name' => $tax->attribute_name, 'search_items' => __('Search ', 'fflcommerce') . $tax->attribute_name, 'all_items' => __('All ', 'fflcommerce') . $tax->attribute_name, 'parent_item' => __('Parent ', 'fflcommerce') . $tax->attribute_name, 'parent_item_colon' => __('Parent ', 'fflcommerce') . $tax->attribute_name . ':', 'edit_item' => __('Edit ', 'fflcommerce') . $tax->attribute_name, 'update_item' => __('Update ', 'fflcommerce') . $tax->attribute_name, 'add_new_item' => __('Add New ', 'fflcommerce') . $tax->attribute_name, 'new_item_name' => __('New ', 'fflcommerce') . $tax->attribute_name), 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'show_ui' => false, 'query_var' => true, 'show_in_nav_menus' => false, 'rewrite' => array('slug' => $category_base . sanitize_title($tax->attribute_name), 'with_front' => false, 'hierarchical' => $hierarchical)));
            }
        }
    }
    register_post_type("shop_order", array('labels' => array('name' => __('Orders', 'fflcommerce'), 'singular_name' => __('Order', 'fflcommerce'), 'all_items' => __('All Orders', 'fflcommerce'), 'add_new' => __('Add New', 'fflcommerce'), 'add_new_item' => __('New Order', 'fflcommerce'), 'edit' => __('Edit', 'fflcommerce'), 'edit_item' => __('Edit Order', 'fflcommerce'), 'new_item' => __('New Order', 'fflcommerce'), 'view' => __('View Order', 'fflcommerce'), 'view_item' => __('View Order', 'fflcommerce'), 'search_items' => __('Search Orders', 'fflcommerce'), 'not_found' => __('No Orders found', 'fflcommerce'), 'not_found_in_trash' => __('No Orders found in trash', 'fflcommerce'), 'parent' => __('Parent Orders', 'fflcommerce')), 'description' => __('This is where store orders are stored.', 'fflcommerce'), 'public' => false, 'show_ui' => true, 'show_in_nav_menus' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'capability_type' => 'shop_order', 'map_meta_cap' => true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('title', 'comments'), 'has_archive' => false, 'menu_position' => 58, 'menu_icon' => 'dashicons-clipboard'));
    register_taxonomy('shop_order_status', array('shop_order'), array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'labels' => array('name' => __('Order statuses', 'fflcommerce'), 'singular_name' => __('Order status', 'fflcommerce'), 'search_items' => __('Search Order statuses', 'fflcommerce'), 'all_items' => __('All  Order statuses', 'fflcommerce'), 'parent_item' => __('Parent Order status', 'fflcommerce'), 'parent_item_colon' => __('Parent Order status:', 'fflcommerce'), 'edit_item' => __('Edit Order status', 'fflcommerce'), 'update_item' => __('Update Order status', 'fflcommerce'), 'add_new_item' => __('Add New Order status', 'fflcommerce'), 'new_item_name' => __('New Order status Name', 'fflcommerce')), 'public' => false, 'show_ui' => false, 'show_in_nav_menus' => false, 'query_var' => true, 'rewrite' => false));
    register_post_type("shop_coupon", array('labels' => array('menu_name' => __('Coupons', 'fflcommerce'), 'name' => __('Coupons', 'fflcommerce'), 'singular_name' => __('Coupon', 'fflcommerce'), 'add_new' => __('Add Coupon', 'fflcommerce'), 'add_new_item' => __('Add New Coupon', 'fflcommerce'), 'edit' => __('Edit', 'fflcommerce'), 'edit_item' => __('Edit Coupon', 'fflcommerce'), 'new_item' => __('New Coupon', 'fflcommerce'), 'view' => __('View Coupons', 'fflcommerce'), 'view_item' => __('View Coupon', 'fflcommerce'), 'search_items' => __('Search Coupons', 'fflcommerce'), 'not_found' => __('No Coupons found', 'fflcommerce'), 'not_found_in_trash' => __('No Coupons found in trash', 'fflcommerce'), 'parent' => __('Parent Coupon', 'fflcommerce')), 'description' => __('This is where you can add new coupons that customers can use in your store.', 'fflcommerce'), 'public' => true, 'show_ui' => true, 'capability_type' => 'shop_coupon', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('title', 'editor'), 'show_in_nav_menus' => false, 'show_in_menu' => 'fflcommerce'));
    register_post_type("shop_email", array('labels' => array('menu_name' => __('Emails', 'fflcommerce'), 'name' => __('Emails', 'fflcommerce'), 'singular_name' => __('Emails', 'fflcommerce'), 'add_new' => __('Add Email', 'fflcommerce'), 'add_new_item' => __('Add New Email', 'fflcommerce'), 'edit' => __('Edit', 'fflcommerce'), 'edit_item' => __('Edit Email', 'fflcommerce'), 'new_item' => __('New Email', 'fflcommerce'), 'view' => __('View Email', 'fflcommerce'), 'view_item' => __('View Email', 'fflcommerce'), 'search_items' => __('Search Email', 'fflcommerce'), 'not_found' => __('No Emils found', 'fflcommerce'), 'not_found_in_trash' => __('No Emails found in trash', 'fflcommerce'), 'parent' => __('Parent Email', 'fflcommerce')), 'description' => __('This is where you can add new emails that customers can receive in your store.', 'fflcommerce'), 'public' => true, 'show_ui' => true, 'capability_type' => 'shop_email', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('title', 'editor'), 'show_in_nav_menus' => false, 'show_in_menu' => 'fflcommerce'));
    if ($options->get('fflcommerce_update_rewrite_rules') == '1') {
        // Re-generate rewrite rules
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
        $options->set('fflcommerce_update_rewrite_rules', '0');
    }
}
function fflcommerce_custom_product_columns($column)
{
    global $post;
    $fflcommerce_options = FFLCommerce_Base::get_options();
    $product = new fflcommerce_product($post->ID);
    switch ($column) {
        case "thumb":
            if ('trash' != $post->post_status) {
                echo '<a class="row-title" href="' . get_edit_post_link($post->ID) . '">';
                echo fflcommerce_get_product_thumbnail('admin_product_list');
                echo '</a>';
            } else {
                echo fflcommerce_get_product_thumbnail('admin_product_list');
            }
            break;
        case "price":
            echo $product->get_price_html();
            break;
        case "featured":
            $url = wp_nonce_url(admin_url('admin-ajax.php?action=fflcommerce-feature-product&product_id=' . $post->ID));
            echo '<a href="' . esc_url($url) . '" title="' . __('Change', 'fflcommerce') . '">';
            if ($product->is_featured()) {
                echo '<a href="' . esc_url($url) . '"><img src="' . fflcommerce::assets_url() . '/assets/images/head_featured_desc.png" alt="yes" />';
            } else {
                echo '<img src="' . fflcommerce::assets_url() . '/assets/images/head_featured.png" alt="no" />';
            }
            echo '</a>';
            break;
        case "stock":
            if (!$product->is_type('grouped') && $product->is_in_stock()) {
                if ($product->managing_stock()) {
                    if ($product->is_type('variable') && $product->stock > 0) {
                        echo $product->stock . ' ' . __('In Stock', 'fflcommerce');
                    } else {
                        if ($product->is_type('variable')) {
                            $stock_total = 0;
                            foreach ($product->get_children() as $child_ID) {
                                $child = $product->get_child($child_ID);
                                $stock_total += (int) $child->stock;
                            }
                            echo $stock_total . ' ' . __('In Stock', 'fflcommerce');
                        } else {
                            echo $product->stock . ' ' . __('In Stock', 'fflcommerce');
                        }
                    }
                } else {
                    echo __('In Stock', 'fflcommerce');
                }
            } elseif ($product->is_type('grouped')) {
                echo __('Parent (no stock)', 'fflcommerce');
            } else {
                echo '<strong class="attention">' . __('Out of Stock', 'fflcommerce') . '</strong>';
            }
            break;
        case "product-type":
            echo __(ucwords($product->product_type), 'fflcommerce');
            echo '<br/>';
            if ($fflcommerce_options->get('fflcommerce_enable_sku', true) == 'yes' && ($sku = get_post_meta($post->ID, 'sku', true))) {
                echo $sku;
            } else {
                echo $post->ID;
            }
            break;
        case "product-date":
            if ('0000-00-00 00:00:00' == $post->post_date) {
                $t_time = $h_time = __('Unpublished', 'fflcommerce');
                $time_diff = 0;
            } else {
                $t_time = get_the_time(__('Y/m/d g:i:s A', 'fflcommerce'));
                $m_time = $post->post_date;
                $time = get_post_time('G', true, $post);
                $time_diff = time() - $time;
                if ($time_diff > 0 && $time_diff < 24 * 60 * 60) {
                    $h_time = sprintf(__('%s ago', 'fflcommerce'), human_time_diff($time));
                } else {
                    $h_time = mysql2date(__('Y/m/d', 'fflcommerce'), $m_time);
                }
            }
            echo '<abbr title="' . esc_attr($t_time) . '">' . apply_filters('post_date_column_time', $h_time, $post) . '</abbr><br />';
            if ('publish' == $post->post_status) {
                _e('Published', 'fflcommerce');
            } elseif ('future' == $post->post_status) {
                if ($time_diff > 0) {
                    echo '<strong class="attention">' . __('Missed schedule', 'fflcommerce') . '</strong>';
                } else {
                    _e('Scheduled', 'fflcommerce');
                }
            } else {
                _e('Draft', 'fflcommerce');
            }
            if ($product->visibility) {
                echo $product->visibility != 'visible' ? '<br /><strong class="attention">' . ucfirst($product->visibility) . '</strong>' : '';
            }
            break;
        case "product-visibility":
            if ($product->visibility) {
                echo $product->visibility == 'Hidden' ? '<strong class="attention">' . ucfirst($product->visibility) . '</strong>' : ucfirst($product->visibility);
            }
            break;
    }
}
Ejemplo n.º 6
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();
}
Ejemplo n.º 7
0
/**
 * @param \fflcommerce_product $product
 * @return array
 */
function get_stock_email_arguments($product)
{
    $options = FFLCommerce_Base::get_options();
    return array('blog_name' => get_bloginfo('name'), 'shop_name' => $options->get('fflcommerce_company_name'), 'shop_address_1' => $options->get('fflcommerce_address_1'), 'shop_address_2' => $options->get('fflcommerce_address_2'), 'shop_tax_number' => $options->get('fflcommerce_tax_number'), 'shop_phone' => $options->get('fflcommerce_company_phone'), 'shop_email' => $options->get('fflcommerce_company_email'), 'product_id' => $product->id, 'product_name' => $product->get_title(), 'sku' => $product->sku);
}
Ejemplo n.º 8
0
 /**
  * Widget
  * Display the widget in the sidebar
  * Save output to the cache if empty
  *
  * @param  array  sidebar arguments
  * @param  array  instance
  */
 function widget($args, $instance)
 {
     // Get the most recent products from the cache
     $cache = wp_cache_get('widget_recent_products', 'widget');
     // If no entry exists use array
     if (!is_array($cache)) {
         $cache = array();
     }
     // If cached get from the cache
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return false;
     }
     // Start buffering
     ob_start();
     extract($args);
     // Set the widget title
     $title = $instance['title'] ? $instance['title'] : __('New Products', 'fflcommerce');
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     // Set number of products to fetch
     if (!($number = $instance['number'])) {
         $number = 10;
     }
     $number = apply_filters('fflcommerce_widget_recent_default_number', $number, $instance, $this->id_base);
     // Set up query
     $query_args = array('posts_per_page' => $number, 'post_type' => 'product', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'desc', 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
     // Show variations of products?  TODO: fix this -JAP-
     /*
     			if( ! $instance['show_variations']) {
     				$query_args['meta_query'] = array(
     					array(
     						'key'		=> 'visibility',
     						'value'		=> array('catalog', 'visible'),
     						'compare'	=> 'IN',
     					),
     				);
     
     				$query_args['parent'] = false;
     			}
     */
     // Run the query
     $q = new WP_Query($query_args);
     // If there are products
     if ($q->have_posts()) {
         // Print the widget wrapper & title
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         // Open the list
         echo '<ul class="product_list_widget">';
         // Print out each product
         while ($q->have_posts()) {
             $q->the_post();
             // Get new fflcommerce_product instance
             $_product = new fflcommerce_product(get_the_ID());
             echo '<li>';
             // Print the product image & title with a link to the permalink
             echo '<a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '">';
             echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : fflcommerce_get_image_placeholder('shop_tiny');
             echo '<span class="js_widget_product_title">' . get_the_title() . '</span>';
             echo '</a>';
             // Print the price with html wrappers
             echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>';
             echo '</li>';
         }
         echo '</ul>';
         // Close the list
         // Print closing widget wrapper
         echo $after_widget;
         // Reset the global $the_post as this query will have stomped on it
         wp_reset_postdata();
     }
     // Flush output buffer and save to cache
     $cache[$args['widget_id']] = ob_get_flush();
     wp_cache_set('widget_recent_products', $cache, 'widget');
 }
    /**
     * Stock Reports
     */
    function fflcommerce_dash_stock_report()
    {
        if (FFLCommerce_Base::get_options()->get('fflcommerce_manage_stock') == 'yes') {
            $lowstockamount = FFLCommerce_Base::get_options()->get('fflcommerce_notify_low_stock_amount');
            if (!is_numeric($lowstockamount)) {
                $lowstockamount = 1;
            }
            $nostockamount = FFLCommerce_Base::get_options()->get('fflcommerce_notify_no_stock_amount');
            if (!is_numeric($nostockamount)) {
                $nostockamount = 0;
            }
            $outofstock = array();
            $lowinstock = array();
            /** @var $wpdb WPDB */
            global $wpdb;
            // Download low in stock products
            $query = $wpdb->prepare("SELECT DISTINCT p.ID, p.post_parent FROM {$wpdb->posts} p\n\t\t\tLEFT JOIN {$wpdb->postmeta} pmm ON p.ID = pmm.post_id\n\t\t\tLEFT JOIN {$wpdb->postmeta} pms ON p.ID = pms.post_id\n\t\t\tLEFT JOIN {$wpdb->postmeta} pmb ON p.ID = pmb.post_id\n\t\t\tWHERE p.post_status = %s AND ((p.post_type = %s AND pmm.meta_value = 1 AND pmm.meta_key = %s AND pmb.meta_key = %s) OR p.post_type = %s) AND pms.meta_key = %s AND\n\t\t\t\t((pms.meta_value <= %d AND pms.meta_value > %d) OR (pms.meta_value = %d AND pmb.meta_value = %s))\n\t\t\t", array('publish', 'product', 'manage_stock', 'backorders', 'product_variation', 'stock', $lowstockamount, $nostockamount, $nostockamount, 'yes'));
            $results = $wpdb->get_results($query);
            foreach ($results as $item) {
                $id = $item->post_parent == 0 ? $item->ID : $item->post_parent;
                $lowinstock[] = array('link' => get_edit_post_link($id), 'title' => get_the_title($item->ID));
            }
            // Download out of stock products
            $query = $wpdb->prepare("SELECT p.ID FROM {$wpdb->posts} p\n\t\t\tLEFT JOIN {$wpdb->postmeta} pmm ON p.ID = pmm.post_id AND pmm.meta_key = %s\n\t\t\tLEFT JOIN {$wpdb->postmeta} pms ON p.ID = pms.post_id AND pms.meta_key = %s\n\t\t\tLEFT JOIN {$wpdb->postmeta} pmb ON p.ID = pmb.post_id AND pmb.meta_key = %s\n\t\t\tWHERE p.post_type = %s AND p.post_status = %s AND pmm.meta_value = 1 AND pms.meta_value = %d AND pmb.meta_value <> %s\n\t\t\t", array('manage_stock', 'stock', 'backorders', 'product', 'publish', $nostockamount, 'yes'));
            $results = $wpdb->get_results($query);
            foreach ($results as $id) {
                $product = new fflcommerce_product($id->ID);
                if (!$product->is_in_stock(true)) {
                    $outofstock[] = array('link' => get_edit_post_link($id->ID), 'title' => get_the_title($id->ID));
                }
            }
            $outofstock = array_splice($outofstock, 0, 20);
            $lowinstock = array_splice($lowinstock, 0, 20);
            ?>
			<div id="fflcommerce_right_now" class="fflcommerce_right_now">
				<div class="table table_content">
					<p class="sub"><?php 
            _e('Low Stock', 'fflcommerce');
            ?>
</p>
					<ol>
						<?php 
            if (count($lowinstock) > 0) {
                ?>
							<?php 
                foreach ($lowinstock as $item) {
                    ?>
								<li><a href="<?php 
                    echo $item['link'];
                    ?>
"><?php 
                    echo $item['title'];
                    ?>
</a></li>
							<?php 
                }
                ?>
						<?php 
            } else {
                ?>
							<li><?php 
                echo __('No products are low in stock.', 'fflcommerce');
                ?>
</li>
						<?php 
            }
            ?>
					</ol>
				</div>
				<div class="table table_discussion">
					<p class="sub"><?php 
            _e('Out of Stock/Backorders', 'fflcommerce');
            ?>
</p>
					<ol>
						<?php 
            if (count($outofstock) > 0) {
                ?>
							<?php 
                foreach ($outofstock as $item) {
                    ?>
								<li><a href="<?php 
                    echo $item['link'];
                    ?>
"><?php 
                    echo $item['title'];
                    ?>
</a></li>
							<?php 
                }
                ?>
						<?php 
            } else {
                ?>
							<li><?php 
                echo __('No products are out of stock.', 'fflcommerce');
                ?>
</li>
						<?php 
            }
            ?>
					</ol>
				</div>
				<br class="clear" />
			</div>
		<?php 
        }
    }
Ejemplo n.º 10
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)
 {
     // Get the most recent products from the cache
     $cache = wp_cache_get('widget_recent_products', 'widget');
     // If no entry exists use array
     if (!is_array($cache)) {
         $cache = array();
     }
     // If cached get from the cache
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return false;
     }
     // Start buffering
     ob_start();
     extract($args);
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Top Rated Products', 'fflcommerce'), $instance, $this->id_base);
     // Set number of products to fetch
     if (!($number = absint($instance['number']))) {
         $number = 5;
     }
     // Set up query
     // Filter the $wpdb query
     add_filter('posts_clauses', array($this, 'order_by_rating'));
     // TODO: Only display products that are in stock
     $query_args = array('posts_per_page' => $number, 'post_type' => 'product', 'post_status' => 'publish', 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
     // Run the query
     $q = new WP_Query($query_args);
     // If there are products
     if ($q->have_posts()) {
         // Print the widget wrapper & title
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         // Open the list
         echo '<ul class="product_list_widget">';
         // Print out each product
         while ($q->have_posts()) {
             $q->the_post();
             $_product = new fflcommerce_product($q->post->ID);
             echo '<li>';
             // Print the title with a link to the permalink
             echo '<a href="' . esc_url(get_permalink()) . '" title="' . esc_attr(get_the_title()) . '">';
             // Print the product image
             echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : fflcommerce_get_image_placeholder('shop_tiny');
             echo '<span class="js_widget_product_title">' . get_the_title() . '</span>';
             echo '</a>';
             // Print the average rating with html wrappers
             echo $_product->get_rating_html('sidebar');
             // Print the price with html wrappers
             echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>';
             echo '</li>';
         }
         echo '</ul>';
         // Close the list
         // Print closing widget wrapper
         echo $after_widget;
         // Reset the global $the_post as this query will have stomped on it
         wp_reset_postdata();
         remove_filter('posts_clauses', array($this, 'order_by_rating'));
     }
     // Flush output buffer and save to cache
     $cache[$args['widget_id']] = ob_get_flush();
     wp_cache_set('widget_recent_products', $cache, 'widget');
 }
Ejemplo n.º 11
0
 /**
  * Form
  * Displays the form for the wordpress admin
  *
  * @param  array  instance
  */
 public function form($instance)
 {
     // Get values from instance
     $title = isset($instance['title']) ? esc_attr($instance['title']) : null;
     $attr_tax = fflcommerce_product::getAttributeTaxonomies();
     // Widget title
     echo '<p>';
     echo '<label for="' . esc_attr($this->get_field_id('title')) . '"> ' . _e('Title:', 'fflcommerce') . '</label>';
     echo '<input type="text" class="widefat" id="' . esc_attr($this->get_field_id('title')) . '" name="' . esc_attr($this->get_field_name('title')) . '" value="' . esc_attr($title) . '" />';
     echo '</p>';
     // Print attribute selector
     if (!empty($attr_tax)) {
         echo '<p>';
         echo '<label for="' . esc_attr($this->get_field_id('attribute')) . '">' . __('Attribute:', 'fflcommerce') . '</label> ';
         echo '<select id="' . esc_attr($this->get_field_id('attribute')) . '" name="' . esc_attr($this->get_field_name('attribute')) . '">';
         foreach ($attr_tax as $tax) {
             if (taxonomy_exists('pa_' . sanitize_title($tax->attribute_name))) {
                 echo '<option value="' . esc_attr($tax->attribute_name) . '" ' . (isset($instance['attribute']) && $instance['attribute'] == $tax->attribute_name ? 'selected' : null) . '>';
                 echo $tax->attribute_name;
                 echo '</option>';
             }
         }
         echo '</select>';
         echo '</p>';
     }
 }
Ejemplo n.º 12
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)
 {
     // Get the most recent products from the cache
     $cache = wp_cache_get('widget_recent_reviews', 'widget');
     // If no entry exists use array
     if (!is_array($cache)) {
         $cache = array();
     }
     // If cached get from the cache
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return false;
     }
     // Start buffering
     ob_start();
     extract($args);
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Recent Reviews', 'fflcommerce'), $instance, $this->id_base);
     // Set number of products to fetch
     if (!($number = absint($instance['number']))) {
         $number = 5;
     }
     // Modify get_comments query to only include products which are visible
     add_filter('comments_clauses', array($this, 'where_product_is_visible'));
     // Get the latest reviews
     $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product'));
     // If there are products
     if ($comments) {
         // Print the widget wrapper & title
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         // Open the list
         echo '<ul class="product_list_widget">';
         // Print out each product
         foreach ($comments as $comment) {
             // Get new fflcommerce_product instance
             $_product = new fflcommerce_product($comment->comment_post_ID);
             // Skip products that are invisible
             if ($_product->visibility == 'hidden') {
                 continue;
             }
             // TODO: Refactor this
             // Apply star size
             $star_size = apply_filters('fflcommerce_star_rating_size_recent_reviews', 16);
             $rating = get_comment_meta($comment->comment_ID, 'rating', true);
             echo '<li>';
             // Print the product image & title with a link to the permalink
             echo '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">';
             // Print the product image
             echo has_post_thumbnail($_product->id) ? get_the_post_thumbnail($_product->id, 'shop_tiny') : fflcommerce_get_image_placeholder('shop_tiny');
             echo '<span class="js_widget_product_title">' . $_product->get_title() . '</span>';
             echo '</a>';
             // Print the star rating
             echo "<div class='star-rating' title='{$rating}'>\n\t\t\t\t\t\t<span style='width:" . $rating * $star_size . "px;'>{$rating} " . __('out of 5', 'fflcommerce') . "</span>\n\t\t\t\t\t</div>";
             // Print the author
             printf(_x('by %1$s', 'author', 'fflcommerce'), get_comment_author($comment->comment_ID));
             echo '</li>';
         }
         echo '</ul>';
         // Close the list
         // Print closing widget wrapper
         echo $after_widget;
         // Remove the filter on comments to stop other queries from being manipulated
         remove_filter('comments_clauses', array($this, 'where_product_is_visible'));
     }
     // Flush output buffer and save to cache
     $cache[$args['widget_id']] = ob_get_flush();
     wp_cache_set('widget_recent_reviews', $cache, 'widget');
 }
/**
 * Add Attribute admin panel
 * Shows the interface for adding new attributes
 *
 * @since    1.0
 * @usedby    fflcommerce_attributes()
 */
function fflcommerce_add_attribute()
{
    ?>
	<div class="wrap fflcommerce">
		<div class="icon32 icon32-attributes" id="icon-fflcommerce"><br /></div>
		<h2><?php 
    _e('Attributes', 'fflcommerce');
    ?>
</h2>
		<br class="clear" />

		<div id="col-container">
			<div id="col-right">
				<div class="col-wrap">
					<table class="widefat fixed" style="width:100%">
						<thead>
						<tr>
							<th scope="col"><?php 
    _e('Label', 'fflcommerce');
    ?>
</th>
							<th scope="col"><?php 
    _e('Slug', 'fflcommerce');
    ?>
</th>
							<th scope="col"><?php 
    _e('Type', 'fflcommerce');
    ?>
</th>
							<th scope="col">&nbsp;</th>
						</tr>
						</thead>
						<tbody>
						<?php 
    $attribute_taxonomies = fflcommerce_product::getAttributeTaxonomies();
    if ($attribute_taxonomies) {
        foreach ($attribute_taxonomies as $tax) {
            $att_title = $tax->attribute_name;
            if (isset($tax->attribute_label)) {
                $att_title = $tax->attribute_label;
            }
            ?>
								<tr>

								<td><a href="edit-tags.php?taxonomy=pa_<?php 
            echo sanitize_title($tax->attribute_name);
            ?>
&amp;post_type=product"><?php 
            echo esc_html(ucwords($att_title));
            ?>
</a>

									<div class="row-actions"><span class="edit"><a
												href="<?php 
            echo esc_url(add_query_arg('edit', $tax->attribute_id, 'admin.php?page=fflcommerce_attributes'));
            ?>
"><?php 
            _e('Edit', 'fflcommerce');
            ?>
</a> | </span><span
											class="delete"><a class="delete"
									                      href="<?php 
            echo esc_url(wp_nonce_url(add_query_arg('delete', $tax->attribute_id, 'admin.php?page=fflcommerce_attributes'), 'fflcommerce-delete-attribute_' . $tax->attribute_id));
            ?>
"><?php 
            _e('Delete', 'fflcommerce');
            ?>
</a></span>
									</div>
								</td>
								<td><?php 
            echo $tax->attribute_name;
            ?>
</td>
								<td><?php 
            echo esc_html(ucwords($tax->attribute_type));
            ?>
</td>
								<td><a href="edit-tags.php?taxonomy=pa_<?php 
            echo sanitize_title($tax->attribute_name);
            ?>
&amp;post_type=product"
								       class="button alignright"><?php 
            _e('Configure&nbsp;terms', 'fflcommerce');
            ?>
</a></td>
								</tr><?php 
        }
    } else {
        ?>
							<tr>
							<td colspan="5"><?php 
        _e('No attributes currently exist.', 'fflcommerce');
        ?>
</td></tr><?php 
    }
    ?>
						</tbody>
					</table>
				</div>
			</div>
			<div id="col-left">
				<div class="col-wrap">
					<div class="form-wrap">
						<h3><?php 
    _e('Add New Attribute', 'fflcommerce');
    ?>
</h3>

						<form action="edit.php?post_type=product&page=fflcommerce_attributes" method="post">
							<?php 
    wp_nonce_field('fflcommerce-add-attribute', '_fflcommerce_csrf');
    ?>
							<div class="form-field">
								<label for="attribute_label"><?php 
    _e('Attribute Label', 'fflcommerce');
    ?>
</label>
								<input name="attribute_label" id="attribute_label" type="text" value="" />

								<p class="description"><?php 
    _e('The label is how it appears on your site.', 'fflcommerce');
    ?>
</p>
							</div>
							<div class="form-field">
								<label for="attribute_name"><?php 
    _e('Attribute Slug', 'fflcommerce');
    ?>
</label>
								<input name="attribute_name" id="attribute_name" type="text" value="" />

								<p class="description"><?php 
    _e('Slug for your attribute (optional).', 'fflcommerce');
    ?>
</p>
							</div>
							<div class="form-field">
								<label for="attribute_type"><?php 
    _e('Attribute type', 'fflcommerce');
    ?>
</label>
								<select name="attribute_type" id="attribute_type" class="postform">
									<option value="multiselect"><?php 
    _e('Multiselect', 'fflcommerce');
    ?>
</option>
									<option value="select"><?php 
    _e('Select', 'fflcommerce');
    ?>
</option>
									<option value="text"><?php 
    _e('Text', 'fflcommerce');
    ?>
</option>
								</select>
							</div>

							<?php 
    do_action('fflcommerce_attribute_admin_add_before_submit');
    ?>

							<p class="submit"><input type="submit" name="add_new_attribute" id="submit" class="button" value="<?php 
    esc_html_e('Add Attribute', 'fflcommerce');
    ?>
"></p>
						</form>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			/* <![CDATA[ */
			jQuery('a.delete').click(function(){
				return confirm("<?php 
    _e('Are you sure you want to delete this?', 'fflcommerce');
    ?>
");
			});
			/* ]]> */
		</script>
	</div>
<?php 
}
Ejemplo n.º 14
0
function fflcommerce_product_thumbnail($post, fflcommerce_product $product)
{
    echo $product->get_image('shop_thumbnail');
}
Ejemplo n.º 15
0
	</tfoot>
	<tbody>
	<?php 
if (sizeof($order->items) > 0) {
    ?>
		<?php 
    foreach ($order->items as $item) {
        ?>
			<?php 
        if (isset($item['variation_id']) && $item['variation_id'] > 0) {
            $product = new fflcommerce_product_variation($item['variation_id']);
            if (is_array($item['variation'])) {
                $product->set_variation_attributes($item['variation']);
            }
        } else {
            $product = new fflcommerce_product($item['id']);
        }
        ?>
			<tr>
				<td><?php 
        echo $product->get_sku();
        ?>
</td>
				<td class="product-name">
					<?php 
        echo $item['name'];
        ?>
			    <?php 
        if ($product instanceof fflcommerce_product_variation) {
            ?>
						<?php 
Ejemplo n.º 16
0
/** Show variation info if set
 *
 * @param fflcommerce_product $product
 * @param array $variation_data
 * @param bool $flat
 * @return string
 */
function fflcommerce_get_formatted_variation(fflcommerce_product $product, $variation_data = array(), $flat = false)
{
    $return = '';
    if (!is_array($variation_data)) {
        $variation_data = array();
    }
    if ($product instanceof fflcommerce_product_variation) {
        $variation_data = array_merge(array_filter($variation_data), array_filter($product->variation_data));
        if (!$flat) {
            $return = '<dl class="variation">';
        }
        $variation_list = array();
        $added = array();
        foreach ($variation_data as $name => $value) {
            if (empty($value)) {
                continue;
            }
            $name = str_replace('tax_', '', $name);
            if (in_array($name, $added)) {
                continue;
            }
            $added[] = $name;
            if (taxonomy_exists('pa_' . $name)) {
                $terms = get_terms('pa_' . $name, array('orderby' => 'slug', 'hide_empty' => '0'));
                foreach ($terms as $term) {
                    if ($term->slug == $value) {
                        $value = $term->name;
                    }
                }
                $name = get_taxonomy('pa_' . $name)->labels->name;
                $name = $product->attribute_label('pa_' . $name);
            }
            // TODO: if it is a custom text attribute, 'pa_' taxonomies are not created and we
            // have no way to get the 'label' as submitted on the Edit Product->Attributes tab.
            // (don't ask me why not, I don't know, but it seems that we should be creating taxonomies)
            // this function really requires the product passed to it for: $product->attribute_label( $name )
            if ($flat) {
                $variation_list[] = $name . ': ' . $value;
            } else {
                $variation_list[] = '<dt>' . $name . ':</dt><dd>' . $value . '</dd>';
            }
        }
        if ($flat) {
            $return .= implode(', ', $variation_list);
        } else {
            $return .= implode('', $variation_list);
        }
        if (!$flat) {
            $return .= '</dl>';
        }
    }
    return $return;
}
Ejemplo n.º 17
0
function fflcommerce_feature_product()
{
    if (!is_admin()) {
        die;
    }
    if (!current_user_can('edit_posts')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    $post_id = isset($_GET['product_id']) && (int) $_GET['product_id'] ? (int) $_GET['product_id'] : '';
    if (!$post_id) {
        die;
    }
    $post = get_post($post_id);
    if (!$post) {
        die;
    }
    if ($post->post_type !== 'product') {
        die;
    }
    $product = new fflcommerce_product($post->ID);
    update_post_meta($post->ID, 'featured', !$product->is_featured());
    $sendback = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer());
    wp_redirect($sendback);
    exit;
}
Ejemplo n.º 18
0
function fflcommerce_downloadable_product_permissions($order_id)
{
    global $wpdb;
    $order = new fflcommerce_order($order_id);
    if (sizeof($order->items) > 0) {
        foreach ($order->items as $item) {
            // if ($item['id']>0) :
            // @todo: Bit of a hack could be improved as id is null/0
            if ((bool) $item['variation_id']) {
                $_product = new fflcommerce_product_variation($item['variation_id']);
                $product_id = $_product->variation_id;
            } else {
                $_product = new fflcommerce_product($item['id']);
                $product_id = $_product->ID;
            }
            if ($_product->exists && $_product->is_type('downloadable')) {
                $user_email = $order->billing_email;
                if ($order->user_id > 0) {
                    $user_info = get_userdata($order->user_id);
                    if ($user_info->user_email) {
                        $user_email = $user_info->user_email;
                    }
                } else {
                    $order->user_id = 0;
                }
                $limit = trim(get_post_meta($_product->id, 'download_limit', true));
                if (!empty($limit)) {
                    $limit = (int) $limit;
                } else {
                    $limit = '';
                }
                // Downloadable product - give access to the customer
                $wpdb->insert($wpdb->prefix . 'fflcommerce_downloadable_product_permissions', array('product_id' => $product_id, 'user_id' => $order->user_id, 'user_email' => $user_email, 'order_key' => $order->order_key, 'downloads_remaining' => $limit), array('%s', '%s', '%s', '%s', '%s'));
            }
            // endif;
        }
    }
}
Ejemplo n.º 19
0
    public function display()
    {
        global $post;
        // Get the attributes
        $attributes = (array) maybe_unserialize(get_post_meta($post->ID, 'product_attributes', true));
        // Get all variations of the product
        $variations = get_posts(array('post_type' => 'product_variation', 'post_status' => array('draft', 'publish'), 'numberposts' => -1, 'orderby' => 'id', 'order' => 'asc', 'post_parent' => $post->ID));
        ?>
		<div id='variable_product_options' class='panel'>
			<?php 
        if ($this->has_variable_attributes($attributes)) {
            ?>
				<div class="toolbar">
					<select name="variation_actions">
						<option value="default"><?php 
            _e('Bulk Actions', 'fflcommerce');
            ?>
</option>
						<option value="remove_all"><?php 
            _e('Remove All Variations', 'fflcommerce');
            ?>
</option>
						<optgroup label="<?php 
            _e('Set All', 'fflcommerce');
            ?>
:">
							<option value="set_all_regular_prices"><?php 
            _e('Regular Prices', 'fflcommerce');
            ?>
</option>
							<option value="set_all_sale_prices"><?php 
            _e('Sale Prices', 'fflcommerce');
            ?>
</option>
							<option value="set_all_stock"><?php 
            _e('Stock', 'fflcommerce');
            ?>
</option>
							<option value="set_all_weight"><?php 
            _e('Weight', 'fflcommerce');
            ?>
</option>
							<option value="set_all_width"><?php 
            _e('Width', 'fflcommerce');
            ?>
</option>
							<option value="set_all_length"><?php 
            _e('Length', 'fflcommerce');
            ?>
</option>
							<option value="set_all_height"><?php 
            _e('Height', 'fflcommerce');
            ?>
</option>
						</optgroup>
					</select>
					<input id="do_actions" type="submit" class="button-secondary" value="<?php 
            _e('Apply', 'fflcommerce');
            ?>
">
					<button type='button' class='button button-seconday add_variation'><?php 
            _e('Add Variation', 'fflcommerce');
            ?>
</button>
				</div>
			<?php 
        }
        ?>
			<div class='fflcommerce_variations'>
				<?php 
        if ($this->has_variable_attributes($attributes)) {
            ?>
					<?php 
            if ($variations) {
                foreach ($variations as $variation) {
                    echo $this->generate_panel($attributes, $variation);
                }
            }
            ?>
				<?php 
        }
        ?>
			</div>
			<div class="toolbar">
				<strong><?php 
        _e('Default selections:', 'fflcommerce');
        ?>
</strong>
				<?php 
        $default_attributes = (array) maybe_unserialize(get_post_meta($post->ID, '_default_attributes', true));
        foreach ($attributes as $attr) {
            // If not variable attribute then skip
            if (!isset($attr['variation'])) {
                continue;
            }
            // Get current value for variation (if set)
            $selected = isset($default_attributes[sanitize_title($attr['name'])]) ? $default_attributes[sanitize_title($attr['name'])] : '';
            // Open the select & set a default value
            echo '<select name="default_attribute_' . sanitize_title($attr['name']) . '" >';
            $product = new fflcommerce_product($post->ID);
            echo '<option value="">' . __('No default', 'fflcommerce') . ' ' . $product->attribute_label('pa_' . $attr['name']) . '&hellip;</option>';
            // Get terms for attribute taxonomy or value if its a custom attribute
            if ($attr['is_taxonomy']) {
                $options = wp_get_object_terms($post->ID, 'pa_' . sanitize_title($attr['name']), array('orderby' => 'slug'));
                if (!is_wp_error($options)) {
                    foreach ($options as $option) {
                        echo '<option value="' . esc_attr($option->slug) . '" ' . selected($selected, $option->slug, false) . '>' . $option->name . '</option>';
                    }
                }
            } else {
                $options = explode(',', $attr['value']);
                foreach ($options as $option) {
                    $option = trim($option);
                    echo '<option ' . selected($selected, $option, false) . ' value="' . esc_attr($option) . '">' . $option . '</option>';
                }
            }
            // Close the select
            echo '</select>';
        }
        ?>
			</div>
		</div>
	<?php 
    }
Ejemplo n.º 20
0
/**
 * Order attributes meta box
 *
 * Displays a list of all attributes which were selected in the order
 */
function fflcommerce_order_attributes_meta_box($post)
{
    $order = new fflcommerce_order($post->ID);
    ?>
    <ul class="order-attributes"><?php 
    foreach ($order->items as $item_id => $item) {
        ?>
        <li>
            <?php 
        do_action('fflcommerce_order_attributes_meta_box_before_item', $item, $item_id);
        ?>
            <b>
                <?php 
        do_action('fflcommerce_order_attributes_meta_box_before_item_title', $item_id);
        ?>
                <?php 
        echo esc_html(isset($item['name']) ? $item['name'] : '');
        ?>
            </b>
            <?php 
        $taxonomies_count = 0;
        // process only variations
        if (isset($item['variation_id']) && !empty($item['variation_id'])) {
            foreach (fflcommerce_product::getAttributeTaxonomies() as $attr_tax) {
                $identifier = 'tax_' . $attr_tax->attribute_name;
                if (!isset($item['variation'][$identifier])) {
                    continue;
                }
                $product = new fflcommerce_product_variation($item['variation_id']);
                $attr_label = str_replace('tax_', '', $identifier);
                $attr_label = $product->attribute_label('pa_' . $attr_label);
                $terms = get_terms('pa_' . $attr_tax->attribute_name, array('orderby' => 'slug', 'hide_empty' => false));
                ?>

                    <div class="order-item-attribute" style="display:block">
                        <span style="display:block"><?php 
                echo esc_html($attr_label);
                ?>
</span>
                        <select name="order_attributes[<?php 
                echo $item_id;
                ?>
][<?php 
                echo $identifier;
                ?>
]">
                            <?php 
                foreach ($terms as $term) {
                    ?>
                                <option <?php 
                    selected($item['variation'][$identifier], $term->slug);
                    ?>
 value="<?php 
                    echo esc_attr($term->slug);
                    ?>
">
                                    <?php 
                    echo esc_html($term->name);
                    ?>
                                </option>
                            <?php 
                }
                ?>
                        </select>
                    </div> <?php 
                $taxonomies_count++;
            }
        }
        if ($taxonomies_count === 0) {
            ?>
                <div class="order-item-attribute no-items-in-order" style="display:block"> <?php 
            _e('No attributes for this item.', 'fflcommerce');
            ?>
                </div><?php 
        }
        do_action('fflcommerce_order_attributes_meta_box_after_item', $item, $item_id);
        ?>
        </li><?php 
    }
    ?>
    </ul>
    <script type="text/javascript">
        /*<![CDATA[*/
            jQuery(function() {
                jQuery(".order-item-attribute select").select2({ width: '255px' });
            });
        /*]]>*/
    </script>
    <?php 
}
Ejemplo n.º 21
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;
    }
Ejemplo n.º 22
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)
 {
     // Get the most recently viewed products from the cache
     $cache = wp_cache_get('widget_recently_viewed_products', 'widget');
     // If no entry exists use array
     if (!is_array($cache)) {
         $cache = array();
     }
     // If cached get from the cache
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return false;
     }
     // Check if session contains recently viewed products
     if (empty(fflcommerce_session::instance()->recently_viewed_products)) {
         return false;
     }
     // Start buffering the output
     ob_start();
     extract($args);
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Recently Viewed Products', 'fflcommerce'), $instance, $this->id_base);
     // Set number of products to fetch
     if (!($number = absint($instance['number']))) {
         $number = 5;
     }
     // Set up query
     $query_args = array('posts_per_page' => $number, 'post_type' => 'product', 'post_status' => 'publish', 'nopaging' => true, 'post__in' => fflcommerce_session::instance()->recently_viewed_products, 'orderby' => 'date', 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
     // Run the query
     $q = new WP_Query($query_args);
     if ($q->have_posts()) {
         // Print the widget wrapper & title
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         // Open the list
         echo '<ul class="product_list_widget recently_viewed_products">';
         // Print out each produt
         while ($q->have_posts()) {
             $q->the_post();
             // Get new fflcommerce_product instance
             $_product = new fflcommerce_product(get_the_ID());
             echo '<li>';
             //print the product title with a permalink
             echo '<a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '">';
             // Print the product image
             echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : fflcommerce_get_image_placeholder('shop_tiny');
             echo '<span class="js_widget_product_title">' . get_the_title() . '</span>';
             echo '</a>';
             // Print the price with wrappers ..yum!
             echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>';
             echo '</li>';
         }
         echo '</ul>';
         // Close the list
         // Print closing widget wrapper
         echo $after_widget;
         // Reset the global $the_post as this query will have stomped on it
         wp_reset_postdata();
     }
     // Flush output buffer and save to cache
     $cache[$args['widget_id']] = ob_get_flush();
     wp_cache_set('widget_recent_products', $cache, 'widget');
 }
Ejemplo n.º 23
0
</span></th>
		<?php 
    do_action('fflcommerce_my_account_orders_thead');
    ?>
	</tr>
	</thead>
	<tbody><?php 
    $orders = new fflcommerce_orders();
    $orders->get_customer_orders(get_current_user_id(), $recent_orders);
    if ($orders->orders) {
        foreach ($orders->orders as $order) {
            /** @var $order fflcommerce_order */
            if ($order->status == 'pending') {
                foreach ($order->items as $item) {
                    $_product = $order->get_product_from_item($item);
                    $temp = new fflcommerce_product($_product->ID);
                    if ($temp->managing_stock() && (!$temp->is_in_stock() || !$temp->has_enough_stock($item['qty']))) {
                        $order->cancel_order(sprintf(__("Product - %s - is now out of stock -- Canceling Order", 'fflcommerce'), $_product->get_title()));
                        ob_get_clean();
                        wp_safe_redirect(apply_filters('fflcommerce_get_myaccount_page_id', get_permalink(fflcommerce_get_page_id('myaccount'))));
                        exit;
                    }
                }
            }
            ?>
<tr class="order">
		<td><?php 
            echo $order->get_order_number();
            ?>
</td>
		<td><time title="<?php 
function fflcommerce_save_bulk_edit()
{
    check_ajax_referer('update-product-stock-price', 'security');
    $post_ids = isset($_POST['post_ids']) && !empty($_POST['post_ids']) ? $_POST['post_ids'] : array();
    $stock = isset($_POST['stock']) ? $_POST['stock'] : NULL;
    $price = isset($_POST['price']) ? $_POST['price'] : NULL;
    if (!empty($post_ids) && is_array($post_ids)) {
        foreach ($post_ids as $post_id) {
            $_product = new fflcommerce_product($post_id);
            if (trim($stock) !== '' && $_product->managing_stock()) {
                $stock = empty($stock) ? 0 : fflcommerce_sanitize_num($stock);
                // TODO: do we need to check to hide products at low stock threshold? (-JAP-)
                update_post_meta($post_id, 'stock', $stock);
            }
            if (trim($price) !== '' && !$_product->is_type(array('grouped'))) {
                update_post_meta($post_id, 'regular_price', fflcommerce_sanitize_num($price));
            }
        }
    }
    die;
}
Ejemplo n.º 25
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 
    }
}
Ejemplo n.º 26
0
 /**
  * Show current filters
  */
 public function current_filters()
 {
     $this->product_ids_titles = array();
     foreach ($this->product_ids as $product_id) {
         $product = new fflcommerce_product($product_id);
         if ($product) {
             $this->product_ids_titles[] = $product->get_title();
         } else {
             $this->product_ids_titles[] = '#' . $product_id;
         }
     }
     echo '<p>' . ' <strong>' . implode(', ', $this->product_ids_titles) . '</strong></p>';
     echo '<p><a class="button" href="' . esc_url(remove_query_arg('product_ids')) . '">' . __('Reset', 'fflcommerce') . '</a></p>';
 }
Ejemplo n.º 27
0
function display_attribute()
{
    global $post;
    // TODO: This needs refactoring
    // This is getting all the taxonomies
    $attribute_taxonomies = fflcommerce_product::getAttributeTaxonomies();
    // Sneaky way of doing sort by desc
    $attribute_taxonomies = array_reverse($attribute_taxonomies);
    // This is whats applied to the product
    $attributes = get_post_meta($post->ID, 'product_attributes', true);
    $i = -1;
    foreach ($attribute_taxonomies as $tax) {
        $i++;
        $attribute = array();
        $attribute_taxonomy_name = sanitize_title($tax->attribute_name);
        if (isset($attributes[$attribute_taxonomy_name])) {
            $attribute = $attributes[$attribute_taxonomy_name];
        }
        $position = isset($attribute['position']) ? $attribute['position'] : -1;
        if ($position >= 0) {
            $allterms = wp_get_object_terms($post->ID, 'pa_' . $attribute_taxonomy_name, array('orderby' => 'slug'));
        } else {
            $allterms = array();
        }
        $has_terms = !(is_wp_error($allterms) || empty($allterms));
        $term_slugs = array();
        if (!is_wp_error($allterms) && !empty($allterms)) {
            foreach ($allterms as $term) {
                $term_slugs[] = $term->slug;
            }
        }
        ?>

		<div class="postbox attribute <?php 
        if ($has_terms) {
            echo 'closed';
        }
        ?>
 <?php 
        echo esc_attr($attribute_taxonomy_name);
        ?>
" data-attribute-name="<?php 
        echo esc_attr($attribute_taxonomy_name);
        ?>
" rel="<?php 
        echo $position;
        ?>
"  <?php 
        if (!$has_terms) {
            echo 'style="display:none"';
        }
        ?>
>
			<button type="button" class="hide_row button"><?php 
        _e('Remove', 'fflcommerce');
        ?>
</button>
			<div class="handlediv" title="<?php 
        _e('Click to toggle', 'fflcommerce');
        ?>
"><br></div>
			<h3 class="handle">
			<?php 
        $label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name;
        echo esc_attr($label);
        ?>
			</h3>

			<input type="hidden" name="attribute_names[<?php 
        echo $i;
        ?>
]" value="<?php 
        echo esc_attr(sanitize_title($tax->attribute_name));
        ?>
" />
			<input type="hidden" name="attribute_is_taxonomy[<?php 
        echo $i;
        ?>
]" value="1" />
			<input type="hidden" name="attribute_enabled[<?php 
        echo $i;
        ?>
]" value="1" />
			<input type="hidden" name="attribute_position[<?php 
        echo $i;
        ?>
]" class="attribute_position" value="<?php 
        echo esc_attr($position);
        ?>
" />

			<div class="inside">
				<table>
					<tr>
						<td class="options">
							<input type="text" class="attribute-name" name="attribute_names[<?php 
        echo $i;
        ?>
]" value="<?php 
        echo esc_attr($label);
        ?>
" disabled="disabled" />

							<div>
								<label>
									<input type="checkbox" <?php 
        checked(boolval(isset($attribute['visible']) ? $attribute['visible'] : 1), true);
        ?>
 name="attribute_visibility[<?php 
        echo $i;
        ?>
]" value="1" /><?php 
        _e('Display on product page', 'fflcommerce');
        ?>
								</label>

								<?php 
        if ($tax->attribute_type != "select") {
            // always disable variation for select elements
            ?>
								<label class="attribute_is_variable">
									<input type="checkbox" <?php 
            checked(boolval(isset($attribute['variation']) ? $attribute['variation'] : 0), true);
            ?>
 name="attribute_variation[<?php 
            echo $i;
            ?>
]" value="1" /><?php 
            _e('Is for variations', 'fflcommerce');
            ?>
								</label>
								<?php 
        }
        ?>
							</div>
						</td>
						<td class="value">
							<?php 
        if ($tax->attribute_type == "select") {
            ?>
								<select name="attribute_values[<?php 
            echo $i;
            ?>
]">
									<option value=""><?php 
            _e('Choose an option&hellip;', 'fflcommerce');
            ?>
</option>
									<?php 
            if (taxonomy_exists('pa_' . $attribute_taxonomy_name)) {
                $terms = get_terms('pa_' . $attribute_taxonomy_name, array('orderby' => 'slug', 'hide_empty' => '0'));
                if ($terms) {
                    foreach ($terms as $term) {
                        printf('<option value="%s" %s>%s</option>', $term->name, selected(in_array($term->slug, $term_slugs), true, false), $term->name);
                    }
                }
            }
            ?>
								</select>

							<?php 
        } elseif ($tax->attribute_type == "multiselect") {
            ?>

								<div class="multiselect">
									<?php 
            if (taxonomy_exists('pa_' . $attribute_taxonomy_name)) {
                $terms = get_terms('pa_' . $attribute_taxonomy_name, array('orderby' => 'slug', 'hide_empty' => '0'));
                if ($terms) {
                    foreach ($terms as $term) {
                        $checked = checked(in_array($term->slug, $term_slugs), true, false);
                        printf('<label %s><input type="checkbox" name="attribute_values[%d][]" value="%s" %s/> %s</label>', !empty($checked) ? 'class="selected"' : '', $i, $term->slug, $checked, $term->name);
                    }
                }
            }
            ?>
								</div>
								<div 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>&nbsp;|
									<a class="toggle" href="#"><?php 
            _e('Toggle', 'fflcommerce');
            ?>
</a>&nbsp;|
									<a class="show-all" href="#"><?php 
            _e('Show All', 'fflcommerce');
            ?>
</a>
								</div>

							<?php 
        } elseif ($tax->attribute_type == "text") {
            ?>
								<textarea name="attribute_values[<?php 
            echo esc_attr($i);
            ?>
]"><?php 
            if ($allterms) {
                $prettynames = array();
                foreach ($allterms as $term) {
                    $prettynames[] = $term->name;
                }
                echo esc_textarea(implode(',', $prettynames));
            }
            ?>
</textarea>
							<?php 
        }
        ?>
						</td>
					</tr>
				</table>
			</div>
		</div>
	<?php 
    }
    ?>
	<?php 
    // Custom Attributes
    if (!empty($attributes)) {
        foreach ($attributes as $attribute) {
            if ($attribute['is_taxonomy']) {
                continue;
            }
            $i++;
            $position = isset($attribute['position']) ? $attribute['position'] : 0;
            ?>
		<div class="postbox attribute closed <?php 
            echo sanitize_title($attribute['name']);
            ?>
" rel="<?php 
            echo isset($attribute['position']) ? $attribute['position'] : 0;
            ?>
">
			<button type="button" class="hide_row button"><?php 
            _e('Remove', 'fflcommerce');
            ?>
</button>
			<div class="handlediv" title="<?php 
            _e('Click to toggle', 'fflcommerce');
            ?>
"><br></div>
			<h3 class="handle"><?php 
            echo esc_attr($attribute['name']);
            ?>
</h3>

			<input type="hidden" name="attribute_is_taxonomy[<?php 
            echo $i;
            ?>
]" value="0" />
			<input type="hidden" name="attribute_enabled[<?php 
            echo $i;
            ?>
]" value="1" />
			<input type="hidden" name="attribute_position[<?php 
            echo $i;
            ?>
]" class="attribute_position" value="<?php 
            echo esc_attr($position);
            ?>
" />

			<div class="inside">
				<table>
					<tr>
						<td class="options">
							<input type="text" class="attribute-name" name="attribute_names[<?php 
            echo $i;
            ?>
]" value="<?php 
            echo esc_attr($attribute['name']);
            ?>
" />

							<div>
								<label>
									<input type="checkbox" <?php 
            checked(boolval(isset($attribute['visible']) ? $attribute['visible'] : 0), true);
            ?>
 name="attribute_visibility[<?php 
            echo $i;
            ?>
]" value="1" /><?php 
            _e('Display on product page', 'fflcommerce');
            ?>
								</label>

								<label class="attribute_is_variable">
									<input type="checkbox" <?php 
            checked(boolval(isset($attribute['variation']) ? $attribute['variation'] : 0), true);
            ?>
 name="attribute_variation[<?php 
            echo $i;
            ?>
]" value="1" /><?php 
            _e('Is for variations', 'fflcommerce');
            ?>
								</label>
							</div>
						</td>

						<td class="value">
							<textarea name="attribute_values[<?php 
            echo esc_attr($i);
            ?>
]" cols="5" rows="2"><?php 
            echo esc_textarea(apply_filters('fflcommerce_product_attribute_value_custom_edit', $attribute['value'], $attribute));
            ?>
</textarea>
						</td>
					</tr>
				</table>
			</div>
		</div>
	<?php 
        }
    }
}
Ejemplo n.º 28
0
 /**
  * Calculate total 'product fixed' and 'product percentage' discounts
  *
  * @param  fflcommerce_product $_product the product we are working with
  * @param  array $values the cart values for this product
  * @return float|int|mixed|void $current_product_discount
  */
 private static function calculate_product_discounts_total($_product, $values)
 {
     $current_product_discount = 0;
     if (!empty(self::$applied_coupons)) {
         foreach (self::$applied_coupons as $code) {
             $coupon_discount = 0;
             $coupon = JS_Coupons::get_coupon($code);
             if (!JS_Coupons::is_valid_coupon_for_product($code, $values)) {
                 continue;
             }
             $price = self::get_options()->get('fflcommerce_tax_after_coupon') == 'yes' ? $_product->get_price_excluding_tax() : $_product->get_price_with_tax();
             switch ($coupon['type']) {
                 case 'fixed_product':
                     $coupon_discount = apply_filters('fflcommerce_coupon_product_fixed_amount', $coupon['amount'], $coupon) * $values['quantity'];
                     if ($coupon_discount > $price * $values['quantity']) {
                         $coupon_discount = $price * $values['quantity'];
                     }
                     break;
                 case 'percent_product':
                     $coupon_discount = $price * $values['quantity'] / 100 * $coupon['amount'];
                     break;
             }
             $current_product_discount += $coupon_discount;
         }
     }
     return $current_product_discount;
 }
Ejemplo n.º 29
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)
 {
     // Get the most recent products from the cache
     $cache = wp_cache_get('widget_recent_products', 'widget');
     // If no entry exists use array
     if (!is_array($cache)) {
         $cache = array();
     }
     // If cached get from the cache
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return false;
     }
     // Start buffering
     ob_start();
     extract($args);
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Special Offers', 'fflcommerce'), $instance, $this->id_base);
     // Set number of products to fetch
     if (!($number = absint($instance['number']))) {
         $number = 5;
     }
     // Set up query
     $time = current_time('timestamp');
     $query_args = array('posts_per_page' => -1, 'post_type' => 'product', 'post_status' => 'publish', 'orderby' => 'rand', 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => 'sale_price_dates_from', 'value' => $time, 'compare' => '<='), array('key' => 'sale_price_dates_to', 'value' => $time, 'compare' => '>=')));
     $q = new WP_Query($query_args);
     // If there are products
     if ($q->have_posts()) {
         // Print the widget wrapper & title
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         // Open the list
         echo '<ul class="product_list_widget">';
         // Print out each product
         for ($i = 0; $q->have_posts() && $i < $number;) {
             $q->the_post();
             // Get new fflcommerce_product instance
             $_product = new fflcommerce_product(get_the_ID());
             // Skip if not on sale
             if (!$_product->is_on_sale()) {
                 continue;
             } else {
                 $i++;
             }
             echo '<li>';
             // Print the product image & title with a link to the permalink
             echo '<a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '">';
             // Print the product image
             echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : fflcommerce_get_image_placeholder('shop_tiny');
             echo '<span class="js_widget_product_title">' . get_the_title() . '</span>';
             echo '</a>';
             // Print the price with html wrappers
             echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>';
             echo '</li>';
         }
         echo '</ul>';
         // Close the list
         // Print closing widget wrapper
         echo $after_widget;
         // Reset the global $the_post as this query will have stomped on it
         wp_reset_postdata();
     }
     ob_get_flush();
 }
 /**
  * Reduce stock levels
  */
 public function reduce_order_stock()
 {
     // Reduce stock levels and do any other actions with products in the cart
     if (sizeof($this->items) > 0) {
         foreach ($this->items as $item) {
             if ($item['id'] > 0) {
                 $_product = $this->get_product_from_item($item);
                 if ($_product instanceof fflcommerce_product_variation) {
                     if ($_product->stock == '-9999999') {
                         // the parent product is used for variation stock tracking
                         $_product = new fflcommerce_product($_product->id);
                     }
                 }
                 if ($_product->exists && $_product->managing_stock()) {
                     $old_stock = $_product->stock;
                     $new_quantity = $_product->reduce_stock($item['qty']);
                     $this->add_order_note(sprintf(__('Item #%s stock reduced from %s to %s.', 'fflcommerce'), $item['id'], $old_stock, $new_quantity));
                     if ($new_quantity < 0) {
                         do_action('fflcommerce_product_on_backorder_notification', $this->id, $_product, $item['qty']);
                     }
                     // stock status notifications
                     if (self::get_options()->get('fflcommerce_notify_no_stock') == 'yes' && self::get_options()->get('fflcommerce_notify_no_stock_amount') >= 0 && self::get_options()->get('fflcommerce_notify_no_stock_amount') >= $new_quantity) {
                         do_action('fflcommerce_no_stock_notification', $_product);
                     } elseif (self::get_options()->get('fflcommerce_notify_low_stock') == 'yes' && self::get_options()->get('fflcommerce_notify_low_stock_amount') && self::get_options()->get('fflcommerce_notify_low_stock_amount') >= $new_quantity) {
                         do_action('fflcommerce_low_stock_notification', $_product);
                     }
                 }
             }
         }
     }
     $this->add_order_note(__('Order item stock reduced successfully.', 'fflcommerce'));
 }