/
specials_widget.php
executable file
·91 lines (81 loc) · 3.19 KB
/
specials_widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
function widget_specials($args)
{
global $wpdb, $table_prefix;
extract($args);
$special_count = $wpdb->get_var("SELECT COUNT(*) AS `count` FROM `".$wpdb->prefix."product_list` WHERE `special` = '1'");
if($special_count > 0)
{
$title = empty($options['title']) ? __(TXT_WPSC_PRODUCT_SPECIALS) : $options['title'];
echo $before_widget;
$full_title = $before_title . $title . $after_title;
echo $full_title;
nzshpcrt_specials();
echo $after_widget;
}
}
function widget_specials_control() { return null; }
function widget_specials_init()
{
if(function_exists('register_sidebar_widget'))
{
register_sidebar_widget(TXT_WPSC_PRODUCT_SPECIALS, 'widget_specials');
}
return;
}
function nzshpcrt_specials($input = null)
{
global $wpdb;
$siteurl = get_option('siteurl');
$sql = "SELECT * FROM `".$wpdb->prefix."product_list` WHERE `special` = '1' ORDER BY RAND() LIMIT 1";
$product = $wpdb->get_results($sql,ARRAY_A) ;
if($product != null)
{
$output = "<div><div>";
foreach($product as $special)
{
$output .= "<strong>".$special['name']."</strong><br /> ";
if($special['image'] != null)
{
$output .= "<img src='$siteurl/wp-content/plugins/wp-shopping-cart/product_images/thumbnails/".$special['image']."' title='".$special['name']."' alt='".$special['name']."' /><br />";
}
$output .= $special['description']."<br />";
// $output .= $special['price'];
$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];
}
if($variations_output[1] == null)
{
$output .= "<span class='oldprice'>".nzshpcrt_currency_display($special['price'], $special['notax'],false)."</span><br />";
}
$output .= "<span id='special_product_price_".$special['id']."'><span class='pricedisplay'>";
$output .= nzshpcrt_currency_display(($special['price'] - $special['special_price']), $special['notax'],false,$product['id']);
$output .= "</span></span><br />";
$output .= "<form id='specials_".$special['id']."' name='$num' method='post' action='#' onsubmit='submitform(this);return false;' >";
$output .= "<input type='hidden' name='prodid' value='".$special['id']."'/>";
$output .= "<input type='hidden' name='item' value='".$special['id']."' />";
if(($special['quantity_limited'] == 1) && ($special['quantity'] < 1))
{
$output .= TXT_WPSC_PRODUCTSOLDOUT."";
}
else
{
//$output .= $variations_processor->display_product_variations($special['id'],true);
$output .= "<input type='submit' name='".TXT_WPSC_ADDTOCART."' value='".TXT_WPSC_ADDTOCART."' />";
}
$output .= "</form>";
}
$output .= "</div></div>";
}
else
{
$output = '';
}
echo $input.$output;
}
add_action('plugins_loaded', 'widget_specials_init');
?>