'widget_wpsc_product_specials',
'description' => __( 'Product Specials Widget', 'wpsc' )
);
$this->WP_Widget( 'wpsc_product_specials', __( 'Product Specials', 'wpsc' ), $widget_ops );
}
/**
* Widget Output
*
* @param $args (array)
* @param $instance (array) Widget values.
*
* @todo Add individual capability checks for each menu item rather than just manage_options.
*/
function widget( $args, $instance ) {
global $wpdb, $table_prefix;
extract( $args );
echo $before_widget;
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Product Specials', 'wpsc' ) : $instance['title'] );
if ( $title )
echo $before_title . $title . $after_title;
wpsc_specials_custom($args, $instance);
echo $after_widget;
}
/**
* Update Widget
*
* @param $new_instance (array) New widget values.
* @param $old_instance (array) Old widget values.
*
* @return (array) New values.
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['number'] = (int)$new_instance['number'];
$instance['show_thumbnails'] = (bool)$new_instance['show_thumbnails'];
$instance['show_description'] = (bool)$new_instance['show_description'];
return $instance;
}
/**
* Widget Options Form
*
* @param $instance (array) Widget values.
*/
function form( $instance ) {
global $wpdb;
// Defaults
$instance = wp_parse_args( (array)$instance, array(
'title' => '',
'show_description' => false,
'show_thumbnails' => false,
'number' => 5
) );
// Values
$title = esc_attr( $instance['title'] );
$number = (int)$instance['number'];
$show_thumbnails = (bool)$instance['show_thumbnails'];
$show_description = (bool)$instance['show_description'];
?>
>
>
tags have been ommitted. Padding and margins should be applied via css.
* 3. Each product is enclosed in a with a 'wpec-special-product' class.
* 4. The product list is enclosed in a
with a 'wpec-special-products' class.
* 5. Function now expect a single paramter with an array of options (used to be a string which prepended the output).
*/
function wpsc_specials_custom( $args = null, $instance ) {
global $wpdb;
$args = wp_parse_args( (array)$args, array( 'number' => 5 ) );
$siteurl = get_option( 'siteurl' );
if ( !$number = (int) $instance['number'] )
$number = 5;
$show_thumbnails = isset($instance['show_thumbnails']) ? (bool)$instance['show_thumbnails'] : FALSE;
$show_description = isset($instance['show_description']) ? (bool)$instance['show_description'] : FALSE;
$excludes = wpsc_specials_custom_excludes_new();
$args = array(
'post_type' => 'wpsc-product',
'caller_get_posts' => 1,
'post_status' => 'publish',
'post_parent' => 0,
'post__not_in' => $excludes,
'posts_per_page' => $number
) ;
$special_products = query_posts( $args );
$output = '';
$product_ids[] = array();
if ( count( $special_products ) > 0 ) {
list( $wp_query, $special_products ) = array( $special_products, $wp_query ); // swap the wpsc_query object
while ( wpsc_have_products() ) : wpsc_the_product();
if(!in_array(wpsc_the_product_id(),$product_ids)):
$product_ids[] = wpsc_the_product_id();
if( $show_thumbnails ):
if ( wpsc_the_product_thumbnail() ) : ?>
get_col("SELECT ID FROM ".$wpdb->posts." JOIN ".$wpdb->postmeta." ON (".$wpdb->posts.".ID = ".$wpdb->postmeta.".post_id) WHERE ".$wpdb->posts.".post_type = 'wpsc-product' AND ".$wpdb->posts.".post_status = 'publish' AND ".$wpdb->postmeta.".meta_key = '_wpsc_special_price' AND ".$wpdb->postmeta.".meta_value = 0 GROUP BY ".$wpdb->posts.".ID ORDER BY ".$wpdb->posts.".post_date DESC");
return $exclude_products;
}
?>