Пример #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;
        }
    }
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;
}
Пример #3
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;
        }
    }
}
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;
    }
}