/
woo-tabbed-category-product-listing.php
185 lines (138 loc) · 4.9 KB
/
woo-tabbed-category-product-listing.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/*
Plugin Name: Woo Tabbed Category Product Listing
Plugin URI: http://www.quantumcloud.com/blog/woocommerce-tabbed-category-wise-product-listing/
Description: A WooCommerce Plugin to dynamically load products from selected category in tabs.
Author: http://www.QuantumCloud.com/
Version: 0.9.1
Author URI:
*/
/**
* Check first if WooCommerce is activated or not
*/
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
// Plugin Code Below
/**
* Loading the plugin specific javascript files.
*/
add_action('init', 'wtcpl_plugin_scripts');
add_action('init', 'wtcpl_scroll_to_scripts');
function wtcpl_plugin_scripts()
{
wp_enqueue_script('wtcpl-product-cat-js', plugins_url('/js/wtcpl-scripts.js', __FILE__), array('jquery'));
}
function wtcpl_scroll_to_scripts()
{
wp_enqueue_script('wtcpl-scroll-to-js', plugins_url('/js/jquery.scrollTo-1.4.3.1-min.js', __FILE__), array('jquery'));
}
/**
* Loading the plugin specific stylesheet files.
*/
function wtcpl_plugin_styles()
{
wp_register_style('wtcpl_plugin_style', plugin_dir_url(__FILE__) . 'css/wtcpl-styles.css');
wp_enqueue_style('wtcpl_plugin_style');
}
function wtcpl_admin_actions()
{
add_options_page("Help", "Tabbed Category", 1, "Help", "wtcpl_help");
}
function wtcpl_help()
{
?>
<div class='wrap'>
<div class="updated notice">
<p>Use the shortcode [wtcpl-product-cat] inside any WordPress post or page to show category wise
WooCommerce
product listing in tabbed format.</p>
</div>
<div class="notice error">
<p>WooCommerce must be installed to use this plugin.</p>
</div>
</div>
<?
}
/**
* The wtcpl_load_products() body
*/
function wtcpl_load_products()
{
?>
<div class="wtcpl_container">
<div id="nav-holder">
<div class="wtcpl_category_nav" id="wtcpl_tabs">
<?php
// echo do_shortcode('[product_categories]');
$args = array(
'number' => $number,
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
'include' => $ids
);
$product_categories = get_terms('product_cat', $args);
// echo "<pre>";
// var_dump($product_categories);
// echo "<pre>";
// die();
?>
<ul>
<?php
$i = 0;
foreach ($product_categories as $cat) {
?>
<li>
<a id="<?php echo $cat->slug; ?>"
class="product-<?php echo $cat->slug; ?><?php if ($i == 0) {
echo " active";
} ?>"
data-name="<?php echo $cat->name; ?>"
href="#"><?php echo $cat->name; ?></a>
</li>
<?php
$i++;
}
?>
</ul>
<!-- <div class="clear"></div>-->
</div>
</div>
<div class="product_content" id="wtcpl_tabs_container">
<?php
$i = 0;
foreach ($product_categories as $cat) {
?>
<div class="each_cat<?php if ($i == 0) {
echo " active";
} ?>" id="product-<?php echo $cat->slug; ?>">
<?php
echo do_shortcode('[product_category category="' . $cat->name . '" per_page="12" columns="3" orderby="date" order="desc"]');
?></div>
<?php $i++;
} ?>
</div>
</div>
<?php
}
/**
* Hooking to WordPress when it initialize
*/
add_action('admin_menu', 'wtcpl_admin_actions');
add_action('wp_enqueue_scripts', 'wtcpl_plugin_styles');
/**
* Register the shortcode
*/
add_shortcode('wtcpl-product-cat', 'wtcpl_load_products');
} else {
add_action('admin_notices', 'wtcpl_notice');
}
function wtcpl_notice()
{
?>
<div class="error notice">
<p>
<strong><?php _e('Please install WooCommerce first, it is required for this plugin to work properly.', 'wtcpl_textdomain'); ?></strong>
</p>
</div>
<?php
}