-
Notifications
You must be signed in to change notification settings - Fork 0
/
woo-cat-product.php
156 lines (124 loc) · 4.43 KB
/
woo-cat-product.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
<?php
/*
Plugin Name: WooCommerce Category Product
Plugin URI:
Description: A WooCommerce Plugin for dynamically load product under a selected category.
Author: QuantumCloud
Version: 1.0
Author URI:
*/
/**
* Check first if WooCommerce is activated or not
*/
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
// Put your plugin code here
/**
* Loading the plugin specific javascript files.
*/
add_action('init', 'woo_plugin_scripts');
add_action('init', 'woo_scroll_to_scripts');
function woo_plugin_scripts()
{
wp_enqueue_script('woo-product-cat-js', plugins_url('/js/woo-scripts.js', __FILE__), array('jquery'));
}
function woo_scroll_to_scripts()
{
wp_enqueue_script('woo-scroll-to-js', plugins_url('/js/jquery.scrollTo-1.4.3.1-min.js', __FILE__), array('jquery'));
}
/**
* Loading the plugin specific stylesheet files.
*/
function woo_plugin_styles()
{
wp_register_style('woo_plugin_style', plugin_dir_url(__FILE__) . 'css/woo-styles.css');
wp_enqueue_style('woo_plugin_style');
}
function woo_admin_actions()
{
add_options_page("Help", "WooCommerce Category Product", 1, "Help", "woo_help");
}
function woo_help()
{
?>
<div class='wrap'>
<?php get_screen_icon(); ?>
<h3>Use the shortcode [product-cat] inside any WordPress post or page to view category wise WooCommerce
product listing. </h3>
<h4>WooCommerce must be installed to use this plugin.</h4>
</div>
<?
}
/**
* The load_cat_product() body
*/
function load_cat_product()
{
?>
<div class="product_container">
<div id="nav-holder">
<div class="woo_category_nav" id="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="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="4" orderby="date" order="desc"]');
?></div>
<?php $i++;
} ?>
</div>
</div>
<?php
}
/**
* Hooking to WordPress when it initialize
*/
add_action('admin_menu', 'woo_admin_actions');
add_action('wp_enqueue_scripts', 'woo_plugin_styles');
/**
* Register the shortcode
*/
add_shortcode('product-cat', 'load_cat_product');
} else {
echo "<h1 style='color:red;'>WooCommerce must be activated before activate this plugin. Otherwise this plugin will not work.</h1>";
}