/** * 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('jigoshop_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', 'jigoshop'), $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 jigoshop_product instance $_product = new jigoshop_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') : jigoshop_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('jigoshop_widget_cache', $cache, 3600 * 3); // 3 hours ahead }
public function column_default($item, $column_name) { global $product; if (!$product || $product->id !== $item->id) { $product = new jigoshop_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', 'jigoshop') . '</mark>'; } else { echo '<mark class="outofstock">' . __('Out of stock', 'jigoshop') . '</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', 'jigoshop'), 'action' => "edit"); if ($product->is_visible()) { $actions['view'] = array('url' => get_permalink($action_id), 'name' => __('View', 'jigoshop'), 'action' => "view"); } $actions = apply_filters('jigoshop_admin_stock_report_product_actions', $actions, $product); foreach ($actions as $action) { printf('<a class="button tips %s" href="%s" data-tip="%s ' . __('product', 'jigoshop') . '">%s</a>', $action['action'], esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name'])); } ?> </p><?php break; } }
/** * 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', 'jigoshop'), $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 jigoshop_product instance $_product = new jigoshop_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') : jigoshop_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(); }
/** * Custom Post Types **/ function jigoshop_post_type() { $options = Jigoshop_Base::get_options(); $shop_page_id = jigoshop_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('jigoshop_prepend_shop_page_to_urls') == 'yes' ? trailingslashit($base_slug) : ''; $category_slug = $options->get('jigoshop_product_category_slug') ? $options->get('jigoshop_product_category_slug') : _x('product-category', 'slug', 'jigoshop'); $tag_slug = $options->get('jigoshop_product_tag_slug') ? $options->get('jigoshop_product_tag_slug') : _x('product-tag', 'slug', 'jigoshop'); $product_base = $options->get('jigoshop_prepend_shop_page_to_product') == 'yes' ? trailingslashit($base_slug) : trailingslashit(_x('product', 'slug', 'jigoshop')); if ($options->get('jigoshop_prepend_shop_page_to_product') == 'yes' && $options->get('jigoshop_prepend_shop_page_to_urls') == 'yes') { $product_base .= trailingslashit(_x('product', 'slug', 'jigoshop')); } if ($options->get('jigoshop_prepend_category_to_product') == 'yes') { $product_base .= trailingslashit('%product_cat%'); } $product_base = untrailingslashit($product_base); register_post_type("product", array('labels' => array('name' => __('Products', 'jigoshop'), 'singular_name' => __('Product', 'jigoshop'), 'all_items' => __('All Products', 'jigoshop'), 'add_new' => __('Add New', 'jigoshop'), 'add_new_item' => __('Add New Product', 'jigoshop'), 'edit' => __('Edit', 'jigoshop'), 'edit_item' => __('Edit Product', 'jigoshop'), 'new_item' => __('New Product', 'jigoshop'), 'view' => __('View Product', 'jigoshop'), 'view_item' => __('View Product', 'jigoshop'), 'search_items' => __('Search Products', 'jigoshop'), 'not_found' => __('No Products found', 'jigoshop'), 'not_found_in_trash' => __('No Products found in trash', 'jigoshop'), 'parent' => __('Parent Product', 'jigoshop')), 'description' => __('This is where you can add new products to your store.', 'jigoshop'), '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', 'jigoshop'), 'singular_name' => __('Variation', 'jigoshop'), 'add_new' => __('Add Variation', 'jigoshop'), 'add_new_item' => __('Add New Variation', 'jigoshop'), 'edit' => __('Edit', 'jigoshop'), 'edit_item' => __('Edit Variation', 'jigoshop'), 'new_item' => __('New Variation', 'jigoshop'), 'view' => __('View Variation', 'jigoshop'), 'view_item' => __('View Variation', 'jigoshop'), 'search_items' => __('Search Variations', 'jigoshop'), 'not_found' => __('No Variations found', 'jigoshop'), 'not_found_in_trash' => __('No Variations found in trash', 'jigoshop'), 'parent' => __('Parent Variation', 'jigoshop')), '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', 'jigoshop'), 'name' => __('Product Categories', 'jigoshop'), 'singular_name' => __('Product Category', 'jigoshop'), 'search_items' => __('Search Product Categories', 'jigoshop'), 'all_items' => __('All Product Categories', 'jigoshop'), 'parent_item' => __('Parent Product Category', 'jigoshop'), 'parent_item_colon' => __('Parent Product Category:', 'jigoshop'), 'edit_item' => __('Edit Product Category', 'jigoshop'), 'update_item' => __('Update Product Category', 'jigoshop'), 'add_new_item' => __('Add New Product Category', 'jigoshop'), 'new_item_name' => __('New Product Category Name', 'jigoshop')), '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', 'jigoshop'), 'name' => __('Product Tags', 'jigoshop'), 'singular_name' => __('Product Tag', 'jigoshop'), 'search_items' => __('Search Product Tags', 'jigoshop'), 'all_items' => __('All Product Tags', 'jigoshop'), 'parent_item' => __('Parent Product Tag', 'jigoshop'), 'parent_item_colon' => __('Parent Product Tag:', 'jigoshop'), 'edit_item' => __('Edit Product Tag', 'jigoshop'), 'update_item' => __('Update Product Tag', 'jigoshop'), 'add_new_item' => __('Add New Product Tag', 'jigoshop'), 'new_item_name' => __('New Product Tag Name', 'jigoshop')), '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 = jigoshop_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 ', 'jigoshop') . $tax->attribute_name, 'all_items' => __('All ', 'jigoshop') . $tax->attribute_name, 'parent_item' => __('Parent ', 'jigoshop') . $tax->attribute_name, 'parent_item_colon' => __('Parent ', 'jigoshop') . $tax->attribute_name . ':', 'edit_item' => __('Edit ', 'jigoshop') . $tax->attribute_name, 'update_item' => __('Update ', 'jigoshop') . $tax->attribute_name, 'add_new_item' => __('Add New ', 'jigoshop') . $tax->attribute_name, 'new_item_name' => __('New ', 'jigoshop') . $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', 'jigoshop'), 'singular_name' => __('Order', 'jigoshop'), 'all_items' => __('All Orders', 'jigoshop'), 'add_new' => __('Add New', 'jigoshop'), 'add_new_item' => __('New Order', 'jigoshop'), 'edit' => __('Edit', 'jigoshop'), 'edit_item' => __('Edit Order', 'jigoshop'), 'new_item' => __('New Order', 'jigoshop'), 'view' => __('View Order', 'jigoshop'), 'view_item' => __('View Order', 'jigoshop'), 'search_items' => __('Search Orders', 'jigoshop'), 'not_found' => __('No Orders found', 'jigoshop'), 'not_found_in_trash' => __('No Orders found in trash', 'jigoshop'), 'parent' => __('Parent Orders', 'jigoshop')), 'description' => __('This is where store orders are stored.', 'jigoshop'), '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', 'jigoshop'), 'singular_name' => __('Order status', 'jigoshop'), 'search_items' => __('Search Order statuses', 'jigoshop'), 'all_items' => __('All Order statuses', 'jigoshop'), 'parent_item' => __('Parent Order status', 'jigoshop'), 'parent_item_colon' => __('Parent Order status:', 'jigoshop'), 'edit_item' => __('Edit Order status', 'jigoshop'), 'update_item' => __('Update Order status', 'jigoshop'), 'add_new_item' => __('Add New Order status', 'jigoshop'), 'new_item_name' => __('New Order status Name', 'jigoshop')), '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', 'jigoshop'), 'name' => __('Coupons', 'jigoshop'), 'singular_name' => __('Coupon', 'jigoshop'), 'add_new' => __('Add Coupon', 'jigoshop'), 'add_new_item' => __('Add New Coupon', 'jigoshop'), 'edit' => __('Edit', 'jigoshop'), 'edit_item' => __('Edit Coupon', 'jigoshop'), 'new_item' => __('New Coupon', 'jigoshop'), 'view' => __('View Coupons', 'jigoshop'), 'view_item' => __('View Coupon', 'jigoshop'), 'search_items' => __('Search Coupons', 'jigoshop'), 'not_found' => __('No Coupons found', 'jigoshop'), 'not_found_in_trash' => __('No Coupons found in trash', 'jigoshop'), 'parent' => __('Parent Coupon', 'jigoshop')), 'description' => __('This is where you can add new coupons that customers can use in your store.', 'jigoshop'), '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' => 'jigoshop')); register_post_type("shop_email", array('labels' => array('menu_name' => __('Emails', 'jigoshop'), 'name' => __('Emails', 'jigoshop'), 'singular_name' => __('Emails', 'jigoshop'), 'add_new' => __('Add Email', 'jigoshop'), 'add_new_item' => __('Add New Email', 'jigoshop'), 'edit' => __('Edit', 'jigoshop'), 'edit_item' => __('Edit Email', 'jigoshop'), 'new_item' => __('New Email', 'jigoshop'), 'view' => __('View Email', 'jigoshop'), 'view_item' => __('View Email', 'jigoshop'), 'search_items' => __('Search Email', 'jigoshop'), 'not_found' => __('No Emails found', 'jigoshop'), 'not_found_in_trash' => __('No Emails found in trash', 'jigoshop'), 'parent' => __('Parent Email', 'jigoshop')), 'description' => __('This is where you can add new emails that customers can receive in your store.', 'jigoshop'), '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' => 'jigoshop')); if ($options->get('jigowatt_update_rewrite_rules') == '1') { // Re-generate rewrite rules global $wp_rewrite; $wp_rewrite->flush_rules(); $options->set('jigowatt_update_rewrite_rules', '0'); } }
function jigoshop_custom_product_columns($column) { global $post; $jigoshop_options = Jigoshop_Base::get_options(); $product = new jigoshop_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 jigoshop_get_product_thumbnail('admin_product_list'); echo '</a>'; } else { echo jigoshop_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=jigoshop-feature-product&product_id=' . $post->ID)); echo '<a href="' . esc_url($url) . '" title="' . __('Change', 'jigoshop') . '">'; if ($product->is_featured()) { echo '<a href="' . esc_url($url) . '"><img src="' . jigoshop::assets_url() . '/assets/images/head_featured_desc.png" alt="yes" />'; } else { echo '<img src="' . jigoshop::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', 'jigoshop'); } 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', 'jigoshop'); } else { echo $product->stock . ' ' . __('In Stock', 'jigoshop'); } } } else { echo __('In Stock', 'jigoshop'); } } elseif ($product->is_type('grouped')) { echo __('Parent (no stock)', 'jigoshop'); } else { echo '<strong class="attention">' . __('Out of Stock', 'jigoshop') . '</strong>'; } break; case "product-type": echo __(ucwords($product->product_type), 'jigoshop'); echo '<br/>'; if ($jigoshop_options->get('jigoshop_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', 'jigoshop'); $time_diff = 0; } else { $t_time = get_the_time(__('Y/m/d g:i:s A', 'jigoshop')); $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', 'jigoshop'), human_time_diff($time)); } else { $h_time = mysql2date(__('Y/m/d', 'jigoshop'), $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', 'jigoshop'); } elseif ('future' == $post->post_status) { if ($time_diff > 0) { echo '<strong class="attention">' . __('Missed schedule', 'jigoshop') . '</strong>'; } else { _e('Scheduled', 'jigoshop'); } } else { _e('Draft', 'jigoshop'); } 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; } }
/** * 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', 'jigoshop'); $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('jigoshop_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; 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 jigoshop_product instance $_product = new jigoshop_product(get_the_ID()); echo '<li><div class="inner">'; // Print the product image & title with a link to the permalink echo '<figure class="featured-thumbnail"><a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '" class="thumb">'; echo '<span class="stroke"></span><span class="image-wrapper">'; $thumb = get_post_thumbnail_id(); $img_url = wp_get_attachment_url($thumb, 'full'); //get img URL $img = aq_resize($img_url, 356, 222, true); $trex = substr(get_the_excerpt(), 0, 120); echo '<img src="' . $img . '" alt="">'; echo '</span>'; echo '</a></figure>'; echo '<div class="js_widget_product_title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></div>'; echo '<span class="js_widget_product_excerpt">' . $trex . '</span>'; // Print the price with html wrappers echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>'; echo '<a href="' . get_permalink() . '" class="js_widget_product_link button">Details</a>'; 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'); }
/** * 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 = jigoshop_product::getAttributeTaxonomies(); // Widget title echo '<p>'; echo '<label for="' . esc_attr($this->get_field_id('title')) . '"> ' . _e('Title:', 'jigoshop') . '</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:', 'jigoshop') . '</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>'; } }
/** * Order attributes meta box * * Displays a list of all attributes which were selected in the order */ function jigoshop_order_attributes_meta_box($post) { $order = new jigoshop_order($post->ID); ?> <ul class="order-attributes"><?php foreach ($order->items as $item_id => $item) { ?> <li> <?php do_action('jigoshop_order_attributes_meta_box_before_item', $item, $item_id); ?> <b> <?php do_action('jigoshop_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 (jigoshop_product::getAttributeTaxonomies() as $attr_tax) { $identifier = 'tax_' . $attr_tax->attribute_name; if (!isset($item['variation'][$identifier])) { continue; } $product = new jigoshop_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.', 'jigoshop'); ?> </div><?php } do_action('jigoshop_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 }
/** Show variation info if set * * @param jigoshop_product $product * @param array $variation_data * @param bool $flat * @return string */ function jigoshop_get_formatted_variation(jigoshop_product $product, $variation_data = array(), $flat = false) { $return = ''; if (!is_array($variation_data)) { $variation_data = array(); } if ($product instanceof jigoshop_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; }
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', 'jigoshop'); ?> </option> <option value="remove_all"><?php _e('Remove All Variations', 'jigoshop'); ?> </option> <optgroup label="<?php _e('Set All', 'jigoshop'); ?> :"> <option value="set_all_regular_prices"><?php _e('Regular Prices', 'jigoshop'); ?> </option> <option value="set_all_sale_prices"><?php _e('Sale Prices', 'jigoshop'); ?> </option> <option value="set_all_stock"><?php _e('Stock', 'jigoshop'); ?> </option> <option value="set_all_weight"><?php _e('Weight', 'jigoshop'); ?> </option> <option value="set_all_width"><?php _e('Width', 'jigoshop'); ?> </option> <option value="set_all_length"><?php _e('Length', 'jigoshop'); ?> </option> <option value="set_all_height"><?php _e('Height', 'jigoshop'); ?> </option> </optgroup> </select> <input id="do_actions" type="submit" class="button-secondary" value="<?php _e('Apply', 'jigoshop'); ?> "> <button type='button' class='button button-seconday add_variation'><?php _e('Add Variation', 'jigoshop'); ?> </button> </div> <?php } ?> <div class='jigoshop_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:', 'jigoshop'); ?> </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 jigoshop_product($post->ID); echo '<option value="">' . __('No default', 'jigoshop') . ' ' . $product->attribute_label('pa_' . $attr['name']) . '…</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 }
/** * calculates the total tax rate that is applied to a product from the applied * tax classes defined on the product. * * @param array $product_rates_array the product rates array * @return mixed null if no taxes or array is null, otherwise the total tax rate to apply */ public static function calculate_total_tax_rate($product_rates_array) { $tax_rate = null; if ($product_rates_array && is_array($product_rates_array) && self::get_options()->get('jigoshop_calc_taxes') == 'yes' && !empty($product_rates_array)) { $tax_rate = 0; foreach ($product_rates_array as $tax_class => $value) { if (jigoshop_product::get_non_compounded_tax($tax_class, $product_rates_array)) { $tax_rate += round(jigoshop_product::get_product_tax_rate($tax_class, $product_rates_array), 4); } else { $tax_rate += round((100 + $tax_rate) * (jigoshop_product::get_product_tax_rate($tax_class, $product_rates_array) / 100), 4); } } } return $tax_rate; }
function jigoshop_downloadable_product_permissions($order_id) { global $wpdb; $order = new jigoshop_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 jigoshop_product_variation($item['variation_id']); $product_id = $_product->variation_id; } else { $_product = new jigoshop_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 . 'jigoshop_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; } } }
/** * 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', 'jigoshop'), $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 jigoshop_product instance $_product = new jigoshop_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') : jigoshop_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(); }
/** * Calculate total 'product fixed' and 'product percentage' discounts * * @param jigoshop_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('jigoshop_tax_after_coupon') == 'yes' ? $_product->get_price_excluding_tax() : $_product->get_price_with_tax(); switch ($coupon['type']) { case 'fixed_product': $coupon_discount = apply_filters('jigoshop_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; }
/** * Get attribute taxonomies. Taxonomies are lazy loaded. * * @return array of stdClass objects representing attributes */ public static function getAttributeTaxonomies() { global $wpdb; if (self::$attribute_taxonomies === null) { self::$attribute_taxonomies = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "jigoshop_attribute_taxonomies;"); } return self::$attribute_taxonomies; }
function jigoshop_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 jigoshop_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; }
/** * @param \jigoshop_product $product * @return array */ function get_stock_email_arguments($product) { $options = Jigoshop_Base::get_options(); return array('blog_name' => get_bloginfo('name'), 'shop_name' => $options->get('jigoshop_company_name'), 'shop_address_1' => $options->get('jigoshop_address_1'), 'shop_address_2' => $options->get('jigoshop_address_2'), 'shop_tax_number' => $options->get('jigoshop_tax_number'), 'shop_phone' => $options->get('jigoshop_company_phone'), 'shop_email' => $options->get('jigoshop_company_email'), 'product_id' => $product->id, 'product_name' => $product->get_title(), 'sku' => $product->sku); }
/** * Reduce stock level of the product * Acts as an alias for modify_stock() * * @param int Amount to reduce by * @return int */ public function reduce_stock($by = -1) { if ($this->stock == '-9999999') { $_parent = new jigoshop_product($this->ID); return $_parent->modify_stock(-$by); } else { return $this->modify_stock(-$by); } }
/** * Add Attribute admin panel * Shows the interface for adding new attributes * * @since 1.0 * @usedby jigoshop_attributes() */ function jigoshop_add_attribute() { ?> <div class="wrap jigoshop"> <div class="icon32 icon32-attributes" id="icon-jigoshop"><br /></div> <h2><?php _e('Attributes', 'jigoshop'); ?> </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', 'jigoshop'); ?> </th> <th scope="col"><?php _e('Slug', 'jigoshop'); ?> </th> <th scope="col"><?php _e('Type', 'jigoshop'); ?> </th> <th scope="col"> </th> </tr> </thead> <tbody> <?php $attribute_taxonomies = jigoshop_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); ?> &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=jigoshop_attributes')); ?> "><?php _e('Edit', 'jigoshop'); ?> </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=jigoshop_attributes'), 'jigoshop-delete-attribute_' . $tax->attribute_id)); ?> "><?php _e('Delete', 'jigoshop'); ?> </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); ?> &post_type=product" class="button alignright"><?php _e('Configure terms', 'jigoshop'); ?> </a></td> </tr><?php } } else { ?> <tr> <td colspan="5"><?php _e('No attributes currently exist.', 'jigoshop'); ?> </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', 'jigoshop'); ?> </h3> <form action="edit.php?post_type=product&page=jigoshop_attributes" method="post"> <?php wp_nonce_field('jigoshop-add-attribute', '_jigoshop_csrf'); ?> <div class="form-field"> <label for="attribute_label"><?php _e('Attribute Label', 'jigoshop'); ?> </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.', 'jigoshop'); ?> </p> </div> <div class="form-field"> <label for="attribute_name"><?php _e('Attribute Slug', 'jigoshop'); ?> </label> <input name="attribute_name" id="attribute_name" type="text" value="" /> <p class="description"><?php _e('Slug for your attribute (optional).', 'jigoshop'); ?> </p> </div> <div class="form-field"> <label for="attribute_type"><?php _e('Attribute type', 'jigoshop'); ?> </label> <select name="attribute_type" id="attribute_type" class="postform"> <option value="multiselect"><?php _e('Multiselect', 'jigoshop'); ?> </option> <option value="select"><?php _e('Select', 'jigoshop'); ?> </option> <option value="text"><?php _e('Text', 'jigoshop'); ?> </option> </select> </div> <?php do_action('jigoshop_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', 'jigoshop'); ?> "></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?', 'jigoshop'); ?> "); }); /* ]]> */ </script> </div> <?php }
function jigoshop_sale_products($atts) { global $columns, $per_page, $paged; extract(shortcode_atts(array('per_page' => Jigoshop_Base::get_options()->get('jigoshop_catalog_per_page'), 'columns' => Jigoshop_Base::get_options()->get('jigoshop_catalog_columns'), 'orderby' => Jigoshop_Base::get_options()->get('jigoshop_catalog_sort_orderby'), 'order' => Jigoshop_Base::get_options()->get('jigoshop_catalog_sort_direction'), 'pagination' => false), $atts)); $ids = jigoshop_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(); jigoshop_get_template_part('loop', 'shop'); if ($pagination) { do_action('jigoshop_pagination'); } wp_reset_postdata(); return ob_get_clean(); }
/** * 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', 'jigoshop'), $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; 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 jigoshop_product instance $_product = new jigoshop_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('jigoshop_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') : jigoshop_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', 'jigoshop') . "</span>\n\t\t\t\t\t</div>"; // Print the author printf(_x('by %1$s', 'author', 'jigoshop'), get_comment_author()); 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'); }
function display_attribute() { global $post; // TODO: This needs refactoring // This is getting all the taxonomies $attribute_taxonomies = jigoshop_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', 'jigoshop'); ?> </button> <div class="handlediv" title="<?php _e('Click to toggle', 'jigoshop'); ?> "><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', 'jigoshop'); ?> </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', 'jigoshop'); ?> </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…', 'jigoshop'); ?> </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', 'jigoshop'); ?> </a> | <a class="uncheck-all" href="#"><?php _e('Uncheck All', 'jigoshop'); ?> </a> | <a class="toggle" href="#"><?php _e('Toggle', 'jigoshop'); ?> </a> | <a class="show-all" href="#"><?php _e('Show All', 'jigoshop'); ?> </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', 'jigoshop'); ?> </button> <div class="handlediv" title="<?php _e('Click to toggle', 'jigoshop'); ?> "><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', 'jigoshop'); ?> </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', 'jigoshop'); ?> </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('jigoshop_product_attribute_value_custom_edit', $attribute['value'], $attribute)); ?> </textarea> </td> </tr> </table> </div> </div> <?php } } }
</span></th> <?php do_action('jigoshop_my_account_orders_thead'); ?> </tr> </thead> <tbody><?php $orders = new jigoshop_orders(); $orders->get_customer_orders(get_current_user_id(), $recent_orders); if ($orders->orders) { foreach ($orders->orders as $order) { /** @var $order jigoshop_order */ if ($order->status == 'pending') { foreach ($order->items as $item) { $_product = $order->get_product_from_item($item); $temp = new jigoshop_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", 'jigoshop'), $_product->get_title())); ob_get_clean(); wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount')))); exit; } } } ?> <tr class="order"> <td><?php echo $order->get_order_number(); ?> </td> <td><time title="<?php
function jigoshop_feature_product () { if( !is_admin() ) die; if( !current_user_can('edit_posts') ) wp_die( __('You do not have sufficient permissions to access this page.') ); if( !check_admin_referer()) wp_die( __('You have taken too long. Please go back and retry.', 'jigoshop') ); $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 jigoshop_product($post->ID); if ($product->is_featured()) update_post_meta($post->ID, 'featured', 'no'); else update_post_meta($post->ID, 'featured', 'yes'); $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() ); wp_safe_redirect( $sendback ); }
/** * Execute changes made in Jigoshop 1.3 * * @since 1.3 */ function jigoshop_upgrade_130() { global $wpdb; /* Update all product variation titles to something useful. */ $args = array( 'post_type' => 'product', 'tax_query' => array( array( 'taxonomy'=> 'product_type', 'terms' => 'variable', 'field' => 'slug', 'operator'=> 'IN' ) ) ); $posts_array = get_posts( $args ); foreach ( $posts_array as $post ) { $product = new jigoshop_product ( $post->ID ); $var = $product->get_children(); foreach ( $var as $id ) { $variation = $product->get_child( $id )->variation_data; $taxes = array(); foreach ( $variation as $k => $v ) : if ( strstr ( $k, 'tax_' ) ) { $tax = substr( $k, 4 ); $taxes[] = sprintf('[%s: %s]', $tax, !empty($v) ? $v : 'Any ' . $tax ); } endforeach; if ( !strstr (get_the_title($id), 'Child Variation' ) ) continue; $title = sprintf('%s - %s', get_the_title($post->ID), implode( $taxes, ' ' ) ); if ( !empty($title) ) $wpdb->update( $wpdb->posts, array('post_title' => $title), array('ID' => $id) ); } } // Convert coupon options to new 'shop_coupon' custom post type and create posts $args = array( 'numberposts' => -1, 'post_type' => 'shop_coupon', 'post_status' => 'publish' ); $new_coupons = (array) get_posts( $args ); if ( empty( $new_coupons )) { /* probably an upgrade from 1.2.3 or less, convert options based coupons */ $coupons = get_option( 'jigoshop_coupons' ); $coupon_data = array( 'post_status' => 'publish', 'post_type' => 'shop_coupon', 'post_author' => 1, 'post_name' => '', 'post_content' => '', 'comment_status' => 'closed' ); if ( ! empty( $coupons )) foreach ( $coupons as $coupon ) { $coupon_data['post_name'] = $coupon['code']; $coupon_data['post_title'] = $coupon['code']; $post_id = wp_insert_post( $coupon_data ); update_post_meta( $post_id, 'type', $coupon['type'] ); update_post_meta( $post_id, 'amount', $coupon['amount'] ); update_post_meta( $post_id, 'include_products', $coupon['products'] ); update_post_meta( $post_id, 'date_from', ($coupon['date_from'] <> 0) ? $coupon['date_from'] : '' ); update_post_meta( $post_id, 'date_to', ($coupon['date_to'] <> 0) ? $coupon['date_to'] : '' ); update_post_meta( $post_id, 'individual_use', ($coupon['individual_use'] == 'yes') ); } } else { /* if CPT based coupons from RC1, convert data for incorrect products meta */ foreach ( $new_coupons as $id => $coupon ) { $product_ids = get_post_meta( $coupon->ID, 'products', true ); if ( $product_ids <> '' ) update_post_meta( $coupon->ID, 'include_products', $product_ids ); delete_post_meta( $coupon->ID, 'products', $product_ids ); } } flush_rewrite_rules( true ); }
/** * 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 jigoshop_product_variation) { if ($_product->stock == '-9999999') { // the parent product is used for variation stock tracking $_product = new jigoshop_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.', 'jigoshop'), $item['id'], $old_stock, $new_quantity)); if ($new_quantity < 0) { do_action('jigoshop_product_on_backorder_notification', $this->id, $_product, $item['qty']); } // stock status notifications if (self::get_options()->get('jigoshop_notify_no_stock') == 'yes' && self::get_options()->get('jigoshop_notify_no_stock_amount') >= 0 && self::get_options()->get('jigoshop_notify_no_stock_amount') >= $new_quantity) { do_action('jigoshop_no_stock_notification', $_product); } elseif (self::get_options()->get('jigoshop_notify_low_stock') == 'yes' && self::get_options()->get('jigoshop_notify_low_stock_amount') && self::get_options()->get('jigoshop_notify_low_stock_amount') >= $new_quantity) { do_action('jigoshop_low_stock_notification', $_product); } } } } } $this->add_order_note(__('Order item stock reduced successfully.', 'jigoshop')); }
/** * 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(jigoshop_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', 'jigoshop'), $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' => jigoshop_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 jigoshop_product instance $_product = new jigoshop_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') : jigoshop_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'); }
/** * Generate the skrill button link **/ public function generate_skrill_form() { $order_id = $_GET['orderId']; $order = new jigoshop_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('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks')); $skrill_args = array('merchant_fields' => 'partner', 'partner' => 'Jigoshop', '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', 'jigoshop'), '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' => Jigoshop_Base::get_options()->get_option('jigoshop_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 jigoshop_product_variation($item['variation_id']); } else { $_product = new jigoshop_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', 'jigoshop'); $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 = Jigoshop_Base::get_options()->get_option('jigoshop_skrill_customer_id') . $skrill_args['transaction_id'] . strtoupper(md5(Jigoshop_Base::get_options()->get_option('jigoshop_skrill_secret_word'))) . $order_total . Jigoshop_Base::get_options()->get_option('jigoshop_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; }
function jigoshop_product_thumbnail($post, jigoshop_product $product) { echo $product->get_image('shop_thumbnail'); }
/** * Show current filters */ public function current_filters() { $this->product_ids_titles = array(); foreach ($this->product_ids as $product_id) { $product = new jigoshop_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', 'jigoshop') . '</a></p>'; }