get_var("SELECT COUNT(*) AS `count` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `special_price` != '0.00' AND `active` IN ('1')"); //exit('COUNT'.$special_count); if($special_count > 0) { $title = empty($options['title']) ? __(__('Product Specials', 'wpsc')) : $options['title']; echo $before_widget; $full_title = $before_title . $title . $after_title; echo $full_title; nzshpcrt_specials(); echo $after_widget; } } function nzshpcrt_specials($input = null) { global $wpdb; $image_width = get_option('product_image_width'); $image_height = get_option('product_image_height'); $siteurl = get_option('siteurl'); $sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `special_price` != '0.00' AND `active` IN ('1') ORDER BY RAND() LIMIT 1"; $product = $wpdb->get_results($sql,ARRAY_A) ; if($product != null) { $output = "
"; foreach($product as $special) { $special['name'] = htmlentities(stripslashes($special['name']), ENT_QUOTES, "UTF-8"); $output .= "".$special['name']."
"; if(is_numeric($special['image'])){ $image_file_name = $wpdb->get_var("SELECT `image` FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `id`= '".$special['image']."' LIMIT 1"); if($image_file_name != '') { $image_path = "index.php?productid=" . $special['id'] . "&width=" . $image_width."&height=" . $image_height. ""; $output .= "".$special[
"; } } //exit('Widget specisl'.get_option('wpsc_special_description')); if(get_option('wpsc_special_description') != '1'){ $output .= $special['description']."
"; } $variations_processor = new nzshpcrt_variations; $variations_output = $variations_processor->display_product_variations($special['id'],true, false, true); $output .= $variations_output[0]; if($variations_output[1] !== null) { $special['price'] = $variations_output[1]; $special['special_price'] = 0; } if($variations_output[1] == null) { $output .= "".nzshpcrt_currency_display($special['price'], $special['notax'],false)."
"; } $output .= ""; $output .= nzshpcrt_currency_display(($special['price'] - $special['special_price']), $special['notax'],false,$product['id']); $output .= "
"; $output .= "
"; $output .= ""; $output .= ""; $output .= ""; if(($special['quantity_limited'] == 1) && ($special['quantity'] < 1)) { $output .= __('This product has sold out.', 'wpsc').""; } else { //$output .= $variations_processor->display_product_variations($special['id'],true); $output .= ""; } $output .= "
"; } $output .= "
"; } else { $output = ''; } echo $input.$output; } function widget_specials_control() { $option_name = 'wpsc-widget_specials'; // because I want to only change this to reuse the code. $options = $newoptions = get_option($option_name); if ( isset($_POST[$option_name]) ) { $newoptions['title'] = strip_tags(stripslashes($_POST[$option_name])); } if(isset($_POST['wpsc_special_description'])){ update_option('wpsc_special_description', $_POST['wpsc_special_description']); }else{ update_option('wpsc_special_description', '0'); } if(get_option('wpsc_special_description') == '1'){ $checked = "checked='checked'"; }else{ $checked = ''; } if ( $options != $newoptions ) { $options = $newoptions; update_option($option_name, $options); } $title = htmlspecialchars($options['title'], ENT_QUOTES); echo "

\n\r"; echo " \n\r"; echo "

\n\r"; echo "

\n\r"; echo " \n\r"; echo "

\n\r"; } function widget_specials_init() { if(function_exists('register_sidebar_widget')) { register_sidebar_widget(__('Product Specials', 'wpsc'), 'widget_specials'); register_widget_control(__('Product Specials', 'wpsc'), 'widget_specials_control'); } return; } add_action('plugins_loaded', 'widget_specials_init'); ?>