コード例 #1
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)
 {
     // Start buffering
     ob_start();
     extract($args);
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Featured 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', 'meta_key' => 'featured', 'meta_value' => '1', '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">';
         // Print 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 fflcommerce_get_product_thumbnail('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();
     }
 }
コード例 #2
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;
    }
}