Version Description
- Complete plugin rewrite
- Added setting for HTTP method (defaults to POST)
- Easier use in themes/templates
- Fix - bug with product tags
- Removed stylesheet (was just one line :o)
- Inserted override for themes that would override the posts_per_page in query
Download this release
Release Info
Developer | sormano |
Plugin | WooCommerce Products Per Page |
Version | 1.1.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.10 to 1.1.0
- admin/options-page.php +0 -193
- assets/css/style.css +0 -3
- includes/class-wppp-dropdown.php +163 -0
- includes/class-wppp-settings.php +303 -0
- objects/wppp-dropdown.php +0 -93
- readme.txt +9 -1
- woocommerce-products-per-page.php +308 -162
admin/options-page.php
DELETED
@@ -1,193 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class wppp_options extends woocommerce_products_per_page {
|
4 |
-
|
5 |
-
|
6 |
-
public function __construct() {
|
7 |
-
|
8 |
-
parent::__construct();
|
9 |
-
|
10 |
-
}
|
11 |
-
|
12 |
-
|
13 |
-
public function wppp_settings_init() {
|
14 |
-
|
15 |
-
register_setting( 'wppp_settings', 'wppp_settings' );
|
16 |
-
|
17 |
-
add_settings_section(
|
18 |
-
'wppp_settings',
|
19 |
-
'WooCommerce Products Per Page',
|
20 |
-
array( $this, 'wppp_section_callback' ),
|
21 |
-
'wppp_settings'
|
22 |
-
);
|
23 |
-
|
24 |
-
|
25 |
-
add_settings_field(
|
26 |
-
'wppp_location',
|
27 |
-
__( 'Dropdown location', 'wppp' ),
|
28 |
-
array( $this, 'wppp_settings_field_location' ),
|
29 |
-
'wppp_settings',
|
30 |
-
'wppp_settings'
|
31 |
-
);
|
32 |
-
|
33 |
-
add_settings_field(
|
34 |
-
'wppp_products_per_page_list',
|
35 |
-
__( 'List of dropdown options', 'wppp' ),
|
36 |
-
array( $this, 'wppp_settings_field_ppp_list' ),
|
37 |
-
'wppp_settings',
|
38 |
-
'wppp_settings'
|
39 |
-
);
|
40 |
-
|
41 |
-
add_settings_field(
|
42 |
-
'wppp_default_ppp',
|
43 |
-
__( 'Default products per page', 'wppp' ),
|
44 |
-
array( $this, 'wppp_settings_field_default_ppp' ),
|
45 |
-
'wppp_settings',
|
46 |
-
'wppp_settings'
|
47 |
-
);
|
48 |
-
|
49 |
-
add_settings_field(
|
50 |
-
'wppp_shop_columns',
|
51 |
-
__( 'Shop columns', 'wppp' ),
|
52 |
-
array( $this, 'wppp_settings_field_shop_columns' ),
|
53 |
-
'wppp_settings',
|
54 |
-
'wppp_settings'
|
55 |
-
);
|
56 |
-
|
57 |
-
add_settings_field(
|
58 |
-
'wppp_ppp_behaviour',
|
59 |
-
__( 'First category page', 'wppp' ),
|
60 |
-
array( $this, 'wppp_settings_field_behaviour' ),
|
61 |
-
'wppp_settings',
|
62 |
-
'wppp_settings'
|
63 |
-
);
|
64 |
-
|
65 |
-
}
|
66 |
-
|
67 |
-
|
68 |
-
public function wppp_render_settings_page() {
|
69 |
-
|
70 |
-
?>
|
71 |
-
<div class="wrap">
|
72 |
-
|
73 |
-
<h2><?php _e( 'WooCommerce Products Per Page', 'wppp' ); ?></h2>
|
74 |
-
|
75 |
-
<form method="POST" action="options.php">
|
76 |
-
<?php
|
77 |
-
settings_fields( 'wppp_settings' );
|
78 |
-
do_settings_sections( 'wppp_settings' );
|
79 |
-
submit_button();
|
80 |
-
?>
|
81 |
-
</form>
|
82 |
-
|
83 |
-
</div>
|
84 |
-
<?php
|
85 |
-
|
86 |
-
}
|
87 |
-
|
88 |
-
public function wppp_settings_field_location() {
|
89 |
-
|
90 |
-
?>
|
91 |
-
<select name="wppp_settings[location]" class="">
|
92 |
-
<option value="top" <?php selected( $this->options['location'], 'top' ); ?>> <?php _e( 'Top', 'wppp' ); ?></option>
|
93 |
-
<option value="bottom" <?php selected( $this->options['location'], 'bottom' ); ?>> <?php _e( 'Bottom', 'wppp' ); ?></option>
|
94 |
-
<option value="topbottom" <?php selected( $this->options['location'], 'topbottom' ); ?>> <?php _e( 'Top/Bottom', 'wppp' ); ?></option>
|
95 |
-
<option value="none" <?php selected( $this->options['location'], 'none' ); ?>> <?php _e( 'None', 'wppp' ); ?></option>
|
96 |
-
</select>
|
97 |
-
<?php
|
98 |
-
|
99 |
-
}
|
100 |
-
|
101 |
-
|
102 |
-
public function wppp_settings_field_ppp_list() {
|
103 |
-
|
104 |
-
?>
|
105 |
-
<label for="productsPerPage">
|
106 |
-
<input type="text" id="productsPerPage" name="wppp_settings[productsPerPage]" value="<?php echo $this->options['productsPerPage']; ?>">
|
107 |
-
<?php _e( 'Seperated by spaces <em>(-1 for all products)</em>', 'wppp' ); ?></label>
|
108 |
-
<?php
|
109 |
-
|
110 |
-
}
|
111 |
-
|
112 |
-
|
113 |
-
public function wppp_settings_field_default_ppp() {
|
114 |
-
|
115 |
-
?>
|
116 |
-
<label for="default_ppp">
|
117 |
-
<input type="number" id="default_ppp" name="wppp_settings[default_ppp]" value="<?php echo $this->options['default_ppp']; ?>">
|
118 |
-
<em><?php _e( '-1 for all products', 'wppp' ); ?></em></label>
|
119 |
-
<?php
|
120 |
-
|
121 |
-
}
|
122 |
-
|
123 |
-
|
124 |
-
public function wppp_settings_field_shop_columns() {
|
125 |
-
|
126 |
-
?>
|
127 |
-
<label for="shop_columns">
|
128 |
-
<input type="number" id="shop_columns" name="wppp_settings[shop_columns]" value="<?php echo $this->options['shop_columns']; ?>">
|
129 |
-
</label>
|
130 |
-
<?php
|
131 |
-
|
132 |
-
}
|
133 |
-
|
134 |
-
|
135 |
-
public function wppp_settings_field_behaviour() {
|
136 |
-
|
137 |
-
?>
|
138 |
-
<label for="behaviour">
|
139 |
-
<input type="checkbox" id="behaviour" name="wppp_settings[behaviour]" value="1" <?php @checked( $this->options['behaviour'], 1 ); ?>>
|
140 |
-
<?php _e( 'When checked and a new number of PPP is selected, the visitor will be send to the first page of the product category', 'wppp' ); ?>
|
141 |
-
</label>
|
142 |
-
<style>
|
143 |
-
.tooltip {
|
144 |
-
width: 200px;
|
145 |
-
height: auto;
|
146 |
-
background-color: rgba( 0,0,0,0.8 );
|
147 |
-
color: #f1f1f1;
|
148 |
-
padding: 10px;
|
149 |
-
border-radius: 10px;
|
150 |
-
display: block;
|
151 |
-
font-family: 'Open Sans', sans-serif;
|
152 |
-
font-size: 14px;
|
153 |
-
display: none;
|
154 |
-
position: relative;
|
155 |
-
top: 15px;
|
156 |
-
left: -12px;
|
157 |
-
}
|
158 |
-
.tooltip:before {
|
159 |
-
border-left: 10px solid transparent;
|
160 |
-
border-right: 10px solid transparent;
|
161 |
-
border-bottom: 10px solid rgba( 0,0,0,0.8 );
|
162 |
-
border-top: 10px solid transparent;
|
163 |
-
content: " ";
|
164 |
-
position: absolute;
|
165 |
-
top: -20px;
|
166 |
-
|
167 |
-
}
|
168 |
-
.tooltip a {
|
169 |
-
color: #f1f1f1;
|
170 |
-
text-decoration: none;
|
171 |
-
}
|
172 |
-
.tooltip a:hover {
|
173 |
-
text-decoration: underline;
|
174 |
-
}
|
175 |
-
*:hover > .tooltip {
|
176 |
-
display: block;
|
177 |
-
}
|
178 |
-
</style>
|
179 |
-
<!-- <div class="dashicons dashicons-info"><span class="tooltip"><a href="http://www.jeroensormani.nl">Read more why this function is in here</a></span></div> -->
|
180 |
-
<?php
|
181 |
-
|
182 |
-
}
|
183 |
-
|
184 |
-
|
185 |
-
public function wppp_section_callback() {
|
186 |
-
|
187 |
-
echo __( 'Configure the WooCommerce Product Per Page settings here.', 'wppp' );
|
188 |
-
|
189 |
-
}
|
190 |
-
|
191 |
-
}
|
192 |
-
|
193 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assets/css/style.css
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
.products-per-page {
|
2 |
-
float: right;
|
3 |
-
}
|
|
|
|
|
|
includes/class-wppp-dropdown.php
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class WPPP_Dropdown
|
7 |
+
*
|
8 |
+
* Products per page dropdown class
|
9 |
+
*
|
10 |
+
* @class WPPP_Dropdown
|
11 |
+
* @version 1.1.0
|
12 |
+
* @author Jeroen Sormani
|
13 |
+
*/
|
14 |
+
class WPPP_Dropdown extends Woocommerce_Products_Per_Page {
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Product per page option array.
|
18 |
+
*
|
19 |
+
* @since 1.0.0
|
20 |
+
* @access public
|
21 |
+
*
|
22 |
+
* @var array $product_per_page_options Array of options.
|
23 |
+
*/
|
24 |
+
public $products_per_page_options;
|
25 |
+
|
26 |
+
|
27 |
+
/**
|
28 |
+
* __construct.
|
29 |
+
*
|
30 |
+
* @since 1.0.0
|
31 |
+
*
|
32 |
+
* @return void.
|
33 |
+
*/
|
34 |
+
public function __construct( $products_per_page_options = null ) {
|
35 |
+
|
36 |
+
parent::__construct();
|
37 |
+
|
38 |
+
$this->products_per_page = $this->wppp_prep_ppp( $products_per_page_options );
|
39 |
+
|
40 |
+
if ( false == $products_per_page_options ) :
|
41 |
+
$this->products_per_page_options = $this->wppp_prep_ppp( apply_filters( 'wppp_products_per_page', $this->settings['productsPerPage'] ) );
|
42 |
+
endif;
|
43 |
+
|
44 |
+
$this->wppp_dropdown();
|
45 |
+
|
46 |
+
}
|
47 |
+
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Products per page dropdown.
|
51 |
+
*
|
52 |
+
* The actual dropdown for to select the number of products per page.
|
53 |
+
*
|
54 |
+
* @since 1.0.0
|
55 |
+
* @deprecated 1.1.0 Use wppp_dropdown() instead (rename).
|
56 |
+
*
|
57 |
+
* @return void.
|
58 |
+
*/
|
59 |
+
public function wppp_create_object() {
|
60 |
+
$this->wppp_dropdown();
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Products per page dropdown.
|
66 |
+
*
|
67 |
+
* The actual dropdown for to select the number of products per page.
|
68 |
+
*
|
69 |
+
* @since 1.1.0
|
70 |
+
*
|
71 |
+
* @global object $wp_query.
|
72 |
+
*
|
73 |
+
* @return void.
|
74 |
+
*/
|
75 |
+
public function wppp_dropdown() {
|
76 |
+
|
77 |
+
global $wp_query;
|
78 |
+
|
79 |
+
$action = '';
|
80 |
+
$cat = '';
|
81 |
+
$cat = $wp_query->get_queried_object();
|
82 |
+
|
83 |
+
// Set action url if option behaviour is true
|
84 |
+
// Paste QUERY string after for filter and orderby support
|
85 |
+
$query_string = ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . add_query_arg( array( 'wppp_ppp' => false ), $_SERVER['QUERY_STRING'] ) : null;
|
86 |
+
|
87 |
+
if ( isset( $cat->term_id ) && isset( $cat->taxonomy ) && isset( $this->settings['behaviour'] ) && true == $this->settings['behaviour'] ) :
|
88 |
+
$action = ' action="' . get_term_link( $cat->term_id, $cat->taxonomy ) . $query_string . '"';
|
89 |
+
elseif ( isset( $this->settings['behaviour'] ) && true == $this->settings['behaviour'] ) :
|
90 |
+
$action = 'action="' . get_permalink( woocommerce_get_page_id( 'shop' ) ) . $query_string . '"';
|
91 |
+
endif;
|
92 |
+
|
93 |
+
$method = 'post'; // default
|
94 |
+
if ( isset( $this->settings['method'] ) && $this->settings['method'] == 'get' ) :
|
95 |
+
$method = 'get';
|
96 |
+
endif;
|
97 |
+
|
98 |
+
// Only show on product categories
|
99 |
+
if ( woocommerce_products_will_display() ) :
|
100 |
+
?>
|
101 |
+
|
102 |
+
<form method="<?php echo $method; ?>" <?php echo $action; ?> style='float: right;' class="form-wppp-select products-per-page">
|
103 |
+
|
104 |
+
<?php do_action( 'wppp_before_dropdown' ); ?>
|
105 |
+
|
106 |
+
<select name="wppp_ppp" onchange="this.form.submit()" class="select wppp-select">
|
107 |
+
|
108 |
+
<?php
|
109 |
+
global $woocommerce;
|
110 |
+
foreach( $this->products_per_page_options as $key => $value ) :
|
111 |
+
|
112 |
+
// Get the right match for the selected option
|
113 |
+
$ppp_session = $woocommerce->session->get( 'products_per_page' );
|
114 |
+
if( isset( $_POST['wppp_ppp'] ) ) :
|
115 |
+
$selected_match = $_POST['wppp_ppp'];
|
116 |
+
elseif( isset( $_GET['wppp_ppp'] ) ):
|
117 |
+
$selected_match = $_GET['wppp_ppp'];
|
118 |
+
elseif ( ! empty( $ppp_session ) ) :
|
119 |
+
$selected_match = $ppp_session;
|
120 |
+
else :
|
121 |
+
$selected_match = $this->settings['default_ppp'];
|
122 |
+
endif;
|
123 |
+
|
124 |
+
?>
|
125 |
+
<option value="<?php echo $value; ?>" <?php selected( $value, $selected_match ); ?>>
|
126 |
+
<?php
|
127 |
+
$ppp_text = apply_filters( 'wppp_ppp_text', __( '%s products per page', 'woocommerce-products-per-page' ), $value );
|
128 |
+
printf( $ppp_text, $value == -1 ? __( 'All', 'wppp' ) : $value ); // Set to 'All' when value is -1
|
129 |
+
?>
|
130 |
+
</option>
|
131 |
+
<?php
|
132 |
+
|
133 |
+
endforeach;
|
134 |
+
?>
|
135 |
+
</select>
|
136 |
+
|
137 |
+
<?php do_action( 'wppp_after_dropdown' ); ?>
|
138 |
+
|
139 |
+
</form>
|
140 |
+
<?php
|
141 |
+
endif;
|
142 |
+
|
143 |
+
}
|
144 |
+
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Prepare dropdown options.
|
148 |
+
*
|
149 |
+
* Prepare the options for the products per page dropdown.
|
150 |
+
*
|
151 |
+
* @since 1.0.0
|
152 |
+
*
|
153 |
+
* @return array of options.
|
154 |
+
*/
|
155 |
+
public function wppp_prep_ppp( $products_per_page ) {
|
156 |
+
|
157 |
+
return explode( ' ', $products_per_page );
|
158 |
+
|
159 |
+
}
|
160 |
+
|
161 |
+
}
|
162 |
+
|
163 |
+
?>
|
includes/class-wppp-settings.php
ADDED
@@ -0,0 +1,303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Class WPPP_Settings
|
6 |
+
*
|
7 |
+
* Initialize settings page
|
8 |
+
*
|
9 |
+
* @class WPPP_Settings
|
10 |
+
* @version 1.1.0
|
11 |
+
* @author Jeroen Sormani
|
12 |
+
*/
|
13 |
+
|
14 |
+
class WPPP_Settings extends Woocommerce_Products_Per_Page {
|
15 |
+
|
16 |
+
|
17 |
+
/**
|
18 |
+
* __construct.
|
19 |
+
*
|
20 |
+
* @since 1.0.0
|
21 |
+
*
|
22 |
+
* @return void.
|
23 |
+
*/
|
24 |
+
public function __construct() {
|
25 |
+
|
26 |
+
parent::__construct();
|
27 |
+
|
28 |
+
}
|
29 |
+
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Register settings.
|
33 |
+
*
|
34 |
+
* Register setting, sections and settings fields.
|
35 |
+
*
|
36 |
+
* @since 1.0.0
|
37 |
+
*
|
38 |
+
* @return void.
|
39 |
+
*/
|
40 |
+
public function wppp_settings_init() {
|
41 |
+
|
42 |
+
register_setting( 'wppp_settings', 'wppp_settings' );
|
43 |
+
|
44 |
+
add_settings_section(
|
45 |
+
'wppp_settings',
|
46 |
+
'WooCommerce Products Per Page',
|
47 |
+
array( $this, 'wppp_section_callback' ),
|
48 |
+
'wppp_settings'
|
49 |
+
);
|
50 |
+
|
51 |
+
|
52 |
+
add_settings_field(
|
53 |
+
'wppp_location',
|
54 |
+
__( 'Dropdown location', 'woocommerce-products-per-page' ),
|
55 |
+
array( $this, 'wppp_settings_field_location' ),
|
56 |
+
'wppp_settings',
|
57 |
+
'wppp_settings'
|
58 |
+
);
|
59 |
+
|
60 |
+
add_settings_field(
|
61 |
+
'wppp_products_per_page_list',
|
62 |
+
__( 'List of dropdown options', 'woocommerce-products-per-page' ),
|
63 |
+
array( $this, 'wppp_settings_field_ppp_list' ),
|
64 |
+
'wppp_settings',
|
65 |
+
'wppp_settings'
|
66 |
+
);
|
67 |
+
|
68 |
+
add_settings_field(
|
69 |
+
'wppp_default_ppp',
|
70 |
+
__( 'Default products per page', 'woocommerce-products-per-page' ),
|
71 |
+
array( $this, 'wppp_settings_field_default_ppp' ),
|
72 |
+
'wppp_settings',
|
73 |
+
'wppp_settings'
|
74 |
+
);
|
75 |
+
|
76 |
+
add_settings_field(
|
77 |
+
'wppp_shop_columns',
|
78 |
+
__( 'Shop columns', 'woocommerce-products-per-page' ),
|
79 |
+
array( $this, 'wppp_settings_field_shop_columns' ),
|
80 |
+
'wppp_settings',
|
81 |
+
'wppp_settings'
|
82 |
+
);
|
83 |
+
|
84 |
+
add_settings_field(
|
85 |
+
'wppp_ppp_behaviour',
|
86 |
+
__( 'First category page', 'woocommerce-products-per-page' ),
|
87 |
+
array( $this, 'wppp_settings_field_behaviour' ),
|
88 |
+
'wppp_settings',
|
89 |
+
'wppp_settings'
|
90 |
+
);
|
91 |
+
|
92 |
+
add_settings_field(
|
93 |
+
'wppp_method',
|
94 |
+
__( 'HTTP method', 'wppp' ),
|
95 |
+
array( $this, 'wppp_settings_field_method' ),
|
96 |
+
'wppp_settings',
|
97 |
+
'wppp_settings'
|
98 |
+
);
|
99 |
+
|
100 |
+
}
|
101 |
+
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Settings page render.
|
105 |
+
*
|
106 |
+
* Load settings fields, sections and submit button.
|
107 |
+
*
|
108 |
+
* @since 1.0.0
|
109 |
+
*
|
110 |
+
* @return void.
|
111 |
+
*/
|
112 |
+
public function wppp_render_settings_page() {
|
113 |
+
|
114 |
+
?><div class="wrap">
|
115 |
+
|
116 |
+
<h2><?php _e( 'WooCommerce Products Per Page', 'woocommerce-products-per-page' ); ?></h2>
|
117 |
+
|
118 |
+
<form method="POST" action="options.php">
|
119 |
+
<?php
|
120 |
+
settings_fields( 'wppp_settings' );
|
121 |
+
do_settings_sections( 'wppp_settings' );
|
122 |
+
submit_button();
|
123 |
+
?>
|
124 |
+
</form>
|
125 |
+
|
126 |
+
</div><?php
|
127 |
+
|
128 |
+
}
|
129 |
+
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Location setting.
|
133 |
+
*
|
134 |
+
* Settings dropdown to select the location of the dropdown.
|
135 |
+
*
|
136 |
+
* @since 1.0.0
|
137 |
+
*
|
138 |
+
* @return void.
|
139 |
+
*/
|
140 |
+
public function wppp_settings_field_location() {
|
141 |
+
|
142 |
+
?><select name="wppp_settings[location]" class="">
|
143 |
+
<option value="top" <?php selected( $this->settings['location'], 'top' ); ?>> <?php _e( 'Top', 'woocommerce-products-per-page' ); ?></option>
|
144 |
+
<option value="bottom" <?php selected( $this->settings['location'], 'bottom' ); ?>> <?php _e( 'Bottom', 'woocommerce-products-per-page' ); ?></option>
|
145 |
+
<option value="topbottom" <?php selected( $this->settings['location'], 'topbottom' ); ?>> <?php _e( 'Top/Bottom', 'woocommerce-products-per-page' ); ?></option>
|
146 |
+
<option value="none" <?php selected( $this->settings['location'], 'none' ); ?>> <?php _e( 'None', 'woocommerce-products-per-page' ); ?></option>
|
147 |
+
</select><?php
|
148 |
+
|
149 |
+
}
|
150 |
+
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Dropdown options input.
|
154 |
+
*
|
155 |
+
* Settings input to set the options for the dropdown. Seperate with space.
|
156 |
+
*
|
157 |
+
* @since 1.0.0
|
158 |
+
*
|
159 |
+
* @return void.
|
160 |
+
*/
|
161 |
+
public function wppp_settings_field_ppp_list() {
|
162 |
+
|
163 |
+
?><label for="products_per_page">
|
164 |
+
<input type="text" id="products_per_page" name="wppp_settings[productsPerPage]" value="<?php echo $this->settings['productsPerPage']; ?>">
|
165 |
+
<?php _e( 'Seperated by spaces <em>(-1 for all products)</em>', 'woocommerce-products-per-page' ); ?></label><?php
|
166 |
+
|
167 |
+
}
|
168 |
+
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Default ppp input.
|
172 |
+
*
|
173 |
+
* Settings input to set the default products per page.
|
174 |
+
*
|
175 |
+
* @since 1.0.0
|
176 |
+
*
|
177 |
+
* @return void.
|
178 |
+
*/
|
179 |
+
public function wppp_settings_field_default_ppp() {
|
180 |
+
|
181 |
+
?><label for="default_ppp">
|
182 |
+
<input type="number" id="default_ppp" name="wppp_settings[default_ppp]" value="<?php echo $this->settings['default_ppp']; ?>">
|
183 |
+
<em><?php _e( '-1 for all products', 'woocommerce-products-per-page' ); ?></em>
|
184 |
+
</label><?php
|
185 |
+
|
186 |
+
}
|
187 |
+
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Shop columns input.
|
191 |
+
*
|
192 |
+
* Settings input to set the shop columns per row.
|
193 |
+
*
|
194 |
+
* @since 1.0.0
|
195 |
+
*
|
196 |
+
* @return void.
|
197 |
+
*/
|
198 |
+
public function wppp_settings_field_shop_columns() {
|
199 |
+
|
200 |
+
?><label for="shop_columns">
|
201 |
+
<input type="number" id="shop_columns" name="wppp_settings[shop_columns]" value="<?php echo $this->settings['shop_columns']; ?>">
|
202 |
+
</label><?php
|
203 |
+
|
204 |
+
}
|
205 |
+
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Behaviour checkbox.
|
209 |
+
*
|
210 |
+
* Rendering method for behaviour checkbox.
|
211 |
+
*
|
212 |
+
* @since 1.0.0
|
213 |
+
*
|
214 |
+
* @return void.
|
215 |
+
*/
|
216 |
+
public function wppp_settings_field_behaviour() {
|
217 |
+
|
218 |
+
?><label for="behaviour">
|
219 |
+
<input type="checkbox" id="behaviour" name="wppp_settings[behaviour]" value="1" <?php @checked( $this->settings['behaviour'], 1 ); ?>>
|
220 |
+
<?php _e( 'When checked and a new number of PPP is selected, the visitor will be send to the first page of the product category', 'woocommerce-products-per-page' ); ?>
|
221 |
+
</label>
|
222 |
+
<style>
|
223 |
+
.tooltip {
|
224 |
+
width: 200px;
|
225 |
+
height: auto;
|
226 |
+
background-color: rgba( 0,0,0,0.8 );
|
227 |
+
color: #f1f1f1;
|
228 |
+
padding: 10px;
|
229 |
+
border-radius: 10px;
|
230 |
+
display: block;
|
231 |
+
font-family: 'Open Sans', sans-serif;
|
232 |
+
font-size: 14px;
|
233 |
+
display: none;
|
234 |
+
position: relative;
|
235 |
+
top: 15px;
|
236 |
+
left: -12px;
|
237 |
+
}
|
238 |
+
.tooltip:before {
|
239 |
+
border-left: 10px solid transparent;
|
240 |
+
border-right: 10px solid transparent;
|
241 |
+
border-bottom: 10px solid rgba( 0,0,0,0.8 );
|
242 |
+
border-top: 10px solid transparent;
|
243 |
+
content: " ";
|
244 |
+
position: absolute;
|
245 |
+
top: -20px;
|
246 |
+
|
247 |
+
}
|
248 |
+
.tooltip a {
|
249 |
+
color: #f1f1f1;
|
250 |
+
text-decoration: none;
|
251 |
+
}
|
252 |
+
.tooltip a:hover {
|
253 |
+
text-decoration: underline;
|
254 |
+
}
|
255 |
+
*:hover > .tooltip {
|
256 |
+
display: block;
|
257 |
+
}
|
258 |
+
</style>
|
259 |
+
<!-- <div class="dashicons dashicons-info"><span class="tooltip"><a href="http://www.jeroensormani.nl">Read more why this function is in here</a></span></div> -->
|
260 |
+
<?php
|
261 |
+
|
262 |
+
}
|
263 |
+
|
264 |
+
|
265 |
+
|
266 |
+
/**
|
267 |
+
* Method checkbox.
|
268 |
+
*
|
269 |
+
* Rendering method for method checkbox.
|
270 |
+
*
|
271 |
+
* @since 1.0.0
|
272 |
+
*
|
273 |
+
* @return void.
|
274 |
+
*/
|
275 |
+
public function wppp_settings_field_method() {
|
276 |
+
|
277 |
+
?><label for="method">
|
278 |
+
<select name="wppp_settings[method]" class="">
|
279 |
+
<option value="post" <?php @selected( $this->settings['method'], 'post' ); ?>> <?php _e( 'POST', 'woocommerce-products-per-page' ); ?></option>
|
280 |
+
<option value="get" <?php @selected( $this->settings['method'], 'get' ); ?>> <?php _e( 'GET', 'woocommerce-products-per-page' ); ?></option>
|
281 |
+
</select>
|
282 |
+
<?php _e( 'GET sends the products per page via the url, POST does this on the background', 'woocommerce-products-per-page' ); ?>
|
283 |
+
</label><?php
|
284 |
+
|
285 |
+
}
|
286 |
+
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Settings page description.
|
290 |
+
*
|
291 |
+
* @since 1.0.0
|
292 |
+
*
|
293 |
+
* @return void.
|
294 |
+
*/
|
295 |
+
public function wppp_section_callback() {
|
296 |
+
|
297 |
+
echo __( 'Configure the WooCommerce Product Per Page settings here.', 'woocommerce-products-per-page' );
|
298 |
+
|
299 |
+
}
|
300 |
+
|
301 |
+
}
|
302 |
+
|
303 |
+
?>
|
objects/wppp-dropdown.php
DELETED
@@ -1,93 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class wppp_dropdown extends woocommerce_products_per_page {
|
4 |
-
|
5 |
-
public $productPerPage;
|
6 |
-
|
7 |
-
public function __construct( $productPerPage = null ) {
|
8 |
-
|
9 |
-
parent::__construct();
|
10 |
-
|
11 |
-
$this->productsPerPage = $this->wppp_prep_ppp( $productPerPage );
|
12 |
-
|
13 |
-
if ( false == $productPerPage )
|
14 |
-
$this->productsPerPage = $this->wppp_prep_ppp( apply_filters( 'wppp_products_per_page', $this->options['productsPerPage'] ) );
|
15 |
-
|
16 |
-
$this->wppp_create_object();
|
17 |
-
|
18 |
-
}
|
19 |
-
|
20 |
-
|
21 |
-
public function wppp_create_object() {
|
22 |
-
|
23 |
-
global $wp_query;
|
24 |
-
|
25 |
-
$cat = '';
|
26 |
-
$cat = $wp_query->get_queried_object();
|
27 |
-
|
28 |
-
// Set action url if option behaviour is true
|
29 |
-
// Paste QUERY string after for filter and orderby support
|
30 |
-
$query_string = !empty( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : null;
|
31 |
-
|
32 |
-
$action = '';
|
33 |
-
if ( isset( $cat->term_id ) && isset( $cat->taxonomy ) && isset( $this->options['behaviour'] ) && true == $cat->term_id && true == $this->options['behaviour'] && 'product_cat' == $cat->taxonomy ) :
|
34 |
-
$action = ' action="' . get_term_link( $cat->term_id, 'product_cat' ) . $query_string . '"';
|
35 |
-
elseif ( isset( $this->options['behaviour'] ) && true == $this->options['behaviour'] ) :
|
36 |
-
$action = 'action="' . get_permalink( woocommerce_get_page_id( 'shop' ) ) . $query_string . '"';
|
37 |
-
endif;
|
38 |
-
|
39 |
-
// Only show on product categories
|
40 |
-
if ( woocommerce_products_will_display() ) :
|
41 |
-
?>
|
42 |
-
|
43 |
-
<form method="post" <?php echo $action; ?> class="form-wppp-select products-per-page">
|
44 |
-
<?php
|
45 |
-
do_action( 'wppp_before_dropdown' );
|
46 |
-
?>
|
47 |
-
<select name="wppp_ppp" onchange="this.form.submit()" class="select wppp-select">
|
48 |
-
|
49 |
-
<?php
|
50 |
-
global $woocommerce;
|
51 |
-
foreach( $this->productsPerPage as $key => $value ) :
|
52 |
-
|
53 |
-
// Get the right match for the selected option
|
54 |
-
$ppp_session = $woocommerce->session->get( 'products_per_page' );
|
55 |
-
if( isset( $_POST['wppp_ppp'] ) ) :
|
56 |
-
$selected_match = $_POST['wppp_ppp'];
|
57 |
-
elseif ( !empty( $ppp_session ) ) :
|
58 |
-
$selected_match = $woocommerce->session->get( 'products_per_page' );
|
59 |
-
else :
|
60 |
-
$selected_match = $this->options['default_ppp'];
|
61 |
-
endif;
|
62 |
-
|
63 |
-
?>
|
64 |
-
<option value="<?php echo $value; ?>" <?php selected( $value, $selected_match ); ?>>
|
65 |
-
<?php
|
66 |
-
$ppp_text = apply_filters( 'wppp_ppp_text', __( '%s products per page', 'wppp' ) );
|
67 |
-
printf( $ppp_text, $value == -1 ? __( 'All', 'wppp' ) : $value ); // Set to 'All' when value is -1
|
68 |
-
?>
|
69 |
-
</option>
|
70 |
-
<?php
|
71 |
-
|
72 |
-
endforeach;
|
73 |
-
?>
|
74 |
-
</select>
|
75 |
-
<?php
|
76 |
-
do_action( 'wppp_after_dropdown' );
|
77 |
-
?>
|
78 |
-
</form>
|
79 |
-
<?php
|
80 |
-
endif;
|
81 |
-
|
82 |
-
}
|
83 |
-
|
84 |
-
|
85 |
-
public function wppp_prep_ppp( $productPerPage ) {
|
86 |
-
|
87 |
-
return explode( ' ', $productPerPage );
|
88 |
-
|
89 |
-
}
|
90 |
-
|
91 |
-
}
|
92 |
-
|
93 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.jeroensormani.nl/donate/
|
|
4 |
Tags: Products per page, woocommerce, woocommerce products, woocommerce products per page, woocommerce displayed products, woocommerce quantity products, woocommerce amount of products, woocommerce number of products, woocommerce shown products
|
5 |
Requires at least: 3.6.0
|
6 |
Tested up to: 3.9.1
|
7 |
-
Stable tag: 1.0
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -43,6 +43,14 @@ Options like:
|
|
43 |
|
44 |
== Changelog ==
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
= 1.0.10 =
|
47 |
* Fix - Notices in debug mode
|
48 |
|
4 |
Tags: Products per page, woocommerce, woocommerce products, woocommerce products per page, woocommerce displayed products, woocommerce quantity products, woocommerce amount of products, woocommerce number of products, woocommerce shown products
|
5 |
Requires at least: 3.6.0
|
6 |
Tested up to: 3.9.1
|
7 |
+
Stable tag: 1.1.0
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
43 |
|
44 |
== Changelog ==
|
45 |
|
46 |
+
= 1.1.0 =
|
47 |
+
* Complete plugin rewrite
|
48 |
+
* Added setting for HTTP method (defaults to POST)
|
49 |
+
* Easier use in themes/templates
|
50 |
+
* Fix - bug with product tags
|
51 |
+
* Removed stylesheet (was just one line :o)
|
52 |
+
* Inserted override for themes that would override the posts_per_page in query
|
53 |
+
|
54 |
= 1.0.10 =
|
55 |
* Fix - Notices in debug mode
|
56 |
|
woocommerce-products-per-page.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Woocommerce Products Per Page
|
4 |
Plugin URI: http://www.jeroensormani.nl/
|
5 |
Description: Integrate a 'products per page' dropdown on your WooCommerce website! Set-up in <strong>seconds</strong>!
|
6 |
-
Version: 1.0
|
7 |
Author: Jeroen Sormani
|
8 |
Author URI: http://www.jeroensormani.nl
|
9 |
|
@@ -27,216 +27,362 @@ Author URI: http://www.jeroensormani.nl
|
|
27 |
* along with WordPress. If not, see <http://www.gnu.org/licenses/>.
|
28 |
*/
|
29 |
|
30 |
-
|
31 |
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
public function __construct() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
//
|
47 |
-
add_action( '
|
48 |
|
49 |
// Check if ppp form is submit
|
50 |
-
add_action( 'init', array( $this, '
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
// Set cookie so PPP will be saved
|
68 |
-
add_action( 'init', array( $this, 'wppp_set_customer_cookie' ), 10 );
|
69 |
-
|
70 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
* Hook into the right look positions of WooCommerce
|
75 |
-
*/
|
76 |
-
public function wppp_hook_locations() {
|
77 |
-
|
78 |
-
if ( $this->options['location'] == 'top' ) :
|
79 |
-
add_action( 'woocommerce_before_shop_loop', array( $this, 'wppp_dropdown_object' ) );
|
80 |
-
elseif ( $this->options['location'] == 'bottom' ) :
|
81 |
-
add_action( 'woocommerce_after_shop_loop', array( $this, 'wppp_dropdown_object' ) );
|
82 |
-
elseif ( $this->options['location'] == 'topbottom' ):
|
83 |
-
add_action( 'woocommerce_before_shop_loop', array( $this, 'wppp_dropdown_object' ) );
|
84 |
-
add_action( 'woocommerce_after_shop_loop', array( $this, 'wppp_dropdown_object' ) );
|
85 |
endif;
|
86 |
|
87 |
-
|
88 |
|
89 |
-
|
90 |
|
91 |
-
global $woocommerce;
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
103 |
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
endif;
|
109 |
|
|
|
|
|
110 |
}
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
global $woocommerce;
|
116 |
|
117 |
if ( isset( $_POST['wppp_ppp'] ) ) :
|
118 |
return $_POST['wppp_ppp'];
|
|
|
|
|
119 |
elseif ( $woocommerce->session->__isset( 'products_per_page' ) ) :
|
120 |
return $woocommerce->session->__get( 'products_per_page' );
|
121 |
else :
|
122 |
-
return $this->
|
123 |
endif;
|
124 |
-
|
125 |
}
|
126 |
|
127 |
-
public function wppp_shop_columns_hook( $columns ) {
|
128 |
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
-
if (
|
132 |
-
$
|
133 |
endif;
|
134 |
|
135 |
-
return $
|
136 |
-
|
137 |
-
}
|
138 |
-
|
139 |
-
|
140 |
-
/* wppp_add_options_menu()
|
141 |
-
*
|
142 |
-
*
|
143 |
-
*/
|
144 |
-
public function wppp_add_options_menu() {
|
145 |
-
|
146 |
-
add_options_page( 'WooCommerce Products Per Page', 'Products Per Page', 'manage_options', 'wppp_settings', array( $this, 'wppp_options_page' ) );
|
147 |
-
|
148 |
-
}
|
149 |
-
|
150 |
-
public function wppp_enqueue_scripts() {
|
151 |
-
|
152 |
-
wp_enqueue_style( 'products-per-page', plugins_url( '/assets/css/style.css', __FILE__ ) );
|
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 |
-
$wppp_options->wppp_render_settings_page();
|
179 |
-
|
180 |
}
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
|
|
187 |
public function wppp_dropdown_object() {
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
new wppp_dropdown();
|
191 |
-
|
192 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
|
194 |
-
|
195 |
-
|
196 |
-
*
|
197 |
-
* Load the configured settings
|
198 |
-
*/
|
199 |
-
public function wppp_load_options() {
|
200 |
-
|
201 |
-
if ( !get_option( 'wppp_settings' ) ) :
|
202 |
-
add_option( 'wppp_settings', $this->wppp_settings_defaults() );
|
203 |
endif;
|
204 |
-
|
205 |
-
$this->options = get_option( 'wppp_settings' );
|
206 |
-
|
207 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
// Set default options to (3x|6x|9x)current Products Per Page
|
217 |
-
$ppp_default =
|
218 |
-
( apply_filters( 'loop_shop_columns', 4 ) * 3) . ' ' .
|
219 |
-
( apply_filters( 'loop_shop_columns', 4 ) * 6) . ' ' .
|
220 |
-
( apply_filters( 'loop_shop_columns', 4 ) * 9) . ' ' .
|
221 |
-
'-1';
|
222 |
-
|
223 |
-
// Set default settings
|
224 |
-
$settings = apply_filters( 'wppp_settings_defaults', array(
|
225 |
-
'location' => 'topbottom',
|
226 |
-
'productsPerPage' => $ppp_default,
|
227 |
-
'default_ppp' => apply_filters( 'loop_shop_per_page', get_option( 'posts_per_page' ) ),
|
228 |
-
'shop_columns' => apply_filters( 'loop_shop_columns', 4 ),
|
229 |
-
) );
|
230 |
-
|
231 |
-
return $settings;
|
232 |
-
|
233 |
}
|
234 |
-
|
235 |
|
236 |
}
|
237 |
-
$wppp = new woocommerce_products_per_page();
|
238 |
|
239 |
-
|
240 |
-
$wppp
|
241 |
-
|
242 |
-
?>
|
3 |
Plugin Name: Woocommerce Products Per Page
|
4 |
Plugin URI: http://www.jeroensormani.nl/
|
5 |
Description: Integrate a 'products per page' dropdown on your WooCommerce website! Set-up in <strong>seconds</strong>!
|
6 |
+
Version: 1.1.0
|
7 |
Author: Jeroen Sormani
|
8 |
Author URI: http://www.jeroensormani.nl
|
9 |
|
27 |
* along with WordPress. If not, see <http://www.gnu.org/licenses/>.
|
28 |
*/
|
29 |
|
30 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
31 |
|
32 |
+
/**
|
33 |
+
* Class Woocommerce_Products_Per_Page
|
34 |
+
*
|
35 |
+
* Main WPPP class, initialized the plugin
|
36 |
+
*
|
37 |
+
* @class Woocommerce_Products_Per_Page
|
38 |
+
* @version 1.1.0
|
39 |
+
* @author Jeroen Sormani
|
40 |
+
*/
|
41 |
|
42 |
+
class Woocommerce_Products_Per_Page {
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Settings from settings page.
|
46 |
+
*
|
47 |
+
* @since 1.1.0
|
48 |
+
* @access public
|
49 |
+
*
|
50 |
+
* @var array $settings Contains all the user settings.
|
51 |
+
*/
|
52 |
+
public $settings;
|
53 |
+
|
54 |
+
|
55 |
+
/**
|
56 |
+
* __construct functon.
|
57 |
+
*
|
58 |
+
* @since 1.0.0
|
59 |
+
*
|
60 |
+
* @return void.
|
61 |
+
*/
|
62 |
public function __construct() {
|
63 |
+
|
64 |
+
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) :
|
65 |
+
if ( ! is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) :
|
66 |
+
return;
|
67 |
+
endif;
|
68 |
+
endif;
|
69 |
+
|
70 |
+
// Initialise settings
|
71 |
+
$this->wppp_init_settings();
|
72 |
+
|
73 |
+
// Initialize hooks
|
74 |
+
$this->wppp_hooks();
|
75 |
+
|
76 |
+
// Load textdomain
|
77 |
+
load_plugin_textdomain( 'woocommerce-products-per-page', false, basename( dirname( __FILE__ ) ) . '/languages' );
|
78 |
+
|
79 |
+
}
|
80 |
+
|
81 |
|
82 |
+
/**
|
83 |
+
* Add all actions and filters.
|
84 |
+
*
|
85 |
+
* @since 1.0.0
|
86 |
+
*
|
87 |
+
* @return int number of columns.
|
88 |
+
*/
|
89 |
+
public function wppp_hooks() {
|
90 |
+
|
91 |
+
// Add admin settings page
|
92 |
+
add_action( 'admin_menu', array( $this, 'wppp_settings_page_menu' ) );
|
93 |
+
|
94 |
+
// Init settings
|
95 |
+
add_action( 'admin_init', array( $this, 'wppp_init_settings_page' ) );
|
96 |
|
97 |
+
// Add filter for product columns
|
98 |
+
add_filter( 'loop_shop_columns', array( $this, 'wppp_loop_shop_columns' ) );
|
99 |
+
|
100 |
+
// Customer number of products per page
|
101 |
+
add_filter( 'loop_shop_per_page', array( $this, 'wppp_loop_shop_per_page' ) );
|
102 |
+
add_filter( 'pre_get_posts', array( $this, 'wppp_pre_get_posts' ), 1, 50 );
|
103 |
|
104 |
+
// Set cookie so PPP will be saved
|
105 |
+
add_action( 'init', array( $this, 'wppp_set_customer_session' ), 10 );
|
106 |
|
107 |
// Check if ppp form is submit
|
108 |
+
add_action( 'init', array( $this, 'wppp_submit_check' ) );
|
109 |
|
110 |
+
}
|
111 |
+
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Initialize admin settings page.
|
115 |
+
*
|
116 |
+
* @since 1.1.0
|
117 |
+
*
|
118 |
+
* @return void.
|
119 |
+
*/
|
120 |
+
public function wppp_settings_page_menu() {
|
121 |
+
add_options_page( 'WooCommerce Products Per Page', 'Products Per Page', 'manage_options', 'wppp_settings', array( $this, 'wppp_settings_page' ) );
|
122 |
+
}
|
123 |
+
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Initialize admin settings page.
|
127 |
+
*
|
128 |
+
* @since 1.0.0
|
129 |
+
*
|
130 |
+
* @return void.
|
131 |
+
*/
|
132 |
+
public function wppp_settings_page() {
|
133 |
+
|
134 |
+
global $wppp_settings;
|
135 |
+
$wppp_settings->wppp_render_settings_page();
|
136 |
|
|
|
|
|
|
|
137 |
}
|
138 |
+
|
139 |
+
|
140 |
+
/**
|
141 |
+
* Initialize settings.
|
142 |
+
*
|
143 |
+
* Settings will be put in an class parameter
|
144 |
+
*
|
145 |
+
* @since 1.1.0
|
146 |
+
*
|
147 |
+
* @return int number of columns.
|
148 |
+
*/
|
149 |
+
public function wppp_init_settings() {
|
150 |
|
151 |
+
if ( !get_option( 'wppp_settings' ) ) :
|
152 |
+
add_option( 'wppp_settings', $this->wppp_settings_defaults() );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
endif;
|
154 |
|
155 |
+
$this->settings = get_option( 'wppp_settings' );
|
156 |
|
157 |
+
}
|
158 |
|
|
|
159 |
|
160 |
+
/**
|
161 |
+
* Default settings
|
162 |
+
*
|
163 |
+
* Default settings will be used when no settings are available
|
164 |
+
*
|
165 |
+
* @since 1.0.0
|
166 |
+
*
|
167 |
+
* @return array default settings.
|
168 |
+
*/
|
169 |
+
public function wppp_settings_defaults() {
|
170 |
|
171 |
+
// Set default options to (3|6|9|All) rows
|
172 |
+
$ppp_default =
|
173 |
+
( apply_filters( 'loop_shop_columns', 4 ) * 3) . ' ' .
|
174 |
+
( apply_filters( 'loop_shop_columns', 4 ) * 6) . ' ' .
|
175 |
+
( apply_filters( 'loop_shop_columns', 4 ) * 9) . ' ' .
|
176 |
+
'-1';
|
177 |
|
178 |
+
// Set default settings
|
179 |
+
$settings = apply_filters( 'wppp_settings_defaults', array(
|
180 |
+
'location' => 'topbottom',
|
181 |
+
'productsPerPage' => $ppp_default,
|
182 |
+
'default_ppp' => apply_filters( 'loop_shop_per_page', get_option( 'posts_per_page' ) ),
|
183 |
+
'shop_columns' => apply_filters( 'loop_shop_columns', 4 ),
|
184 |
+
'behaviour' => '0',
|
185 |
+
'method' => 'post',
|
186 |
+
) );
|
187 |
|
188 |
+
return $settings;
|
189 |
+
|
190 |
+
}
|
191 |
+
|
192 |
+
|
193 |
+
/**
|
194 |
+
* Initialise admin settings.
|
195 |
+
*
|
196 |
+
* Initializes settings, but doesn't display them.
|
197 |
+
*
|
198 |
+
* @since 1.1.0
|
199 |
+
*
|
200 |
+
* @return void.
|
201 |
+
*/
|
202 |
+
public function wppp_init_settings_page() {
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Settings page class
|
206 |
+
*/
|
207 |
+
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wppp-settings.php';
|
208 |
+
|
209 |
+
global $wppp_settings;
|
210 |
+
$wppp_settings = new WPPP_Settings();
|
211 |
+
$wppp_settings->wppp_settings_init();
|
212 |
+
|
213 |
+
}
|
214 |
+
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Shop columns.
|
218 |
+
*
|
219 |
+
* Set number of columns (products per row).
|
220 |
+
*
|
221 |
+
* @since 1.0.0
|
222 |
+
*
|
223 |
+
* @return int Number of columns.
|
224 |
+
*/
|
225 |
+
public function wppp_loop_shop_columns( $columns ) {
|
226 |
+
|
227 |
+
if ( $this->settings && $this->settings['shop_columns'] > 0 ) :
|
228 |
+
$columns = $this->settings['shop_columns'];
|
229 |
endif;
|
230 |
|
231 |
+
return $columns;
|
232 |
+
|
233 |
}
|
234 |
+
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Per page hook.
|
238 |
+
*
|
239 |
+
* Return the number of products per page to the hook
|
240 |
+
*
|
241 |
+
* @since 1.0.0
|
242 |
+
*
|
243 |
+
* @return int Products per page.
|
244 |
+
*/
|
245 |
+
public function wppp_loop_shop_per_page() {
|
246 |
|
247 |
global $woocommerce;
|
248 |
|
249 |
if ( isset( $_POST['wppp_ppp'] ) ) :
|
250 |
return $_POST['wppp_ppp'];
|
251 |
+
elseif ( isset( $_GET['wppp_ppp'] ) ) :
|
252 |
+
return $_GET['wppp_ppp'];
|
253 |
elseif ( $woocommerce->session->__isset( 'products_per_page' ) ) :
|
254 |
return $woocommerce->session->__get( 'products_per_page' );
|
255 |
else :
|
256 |
+
return $this->settings['default_ppp'];
|
257 |
endif;
|
258 |
+
|
259 |
}
|
260 |
|
|
|
261 |
|
262 |
+
/**
|
263 |
+
* Posts per page.
|
264 |
+
*
|
265 |
+
* Set the number of posts per page on a hard way, build in fix for many themes who override the offical loop_shop_per_page filter.
|
266 |
+
*
|
267 |
+
* @since 1.1.0
|
268 |
+
*
|
269 |
+
* @return object Query object
|
270 |
+
*/
|
271 |
+
public function wppp_pre_get_posts( $q ) {
|
272 |
|
273 |
+
if ( function_exists( 'woocommerce_products_will_display' ) && woocommerce_products_will_display() ) :
|
274 |
+
$q->set( 'posts_per_page', $this->wppp_loop_shop_per_page() );
|
275 |
endif;
|
276 |
|
277 |
+
return $q;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
|
279 |
}
|
280 |
+
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Add dropdown.
|
284 |
+
*
|
285 |
+
* Add the dropdown to the category/shop pages.
|
286 |
+
*
|
287 |
+
* @since 1.0.0
|
288 |
+
*
|
289 |
+
* @return void.
|
290 |
+
*/
|
291 |
+
public function wppp_shop_hooks() {
|
292 |
+
|
293 |
+
if ( $this->settings['location'] == 'top' ) :
|
294 |
+
add_action( 'woocommerce_before_shop_loop', array( $this, 'wppp_dropdown' ) );
|
295 |
+
elseif ( $this->settings['location'] == 'bottom' ) :
|
296 |
+
add_action( 'woocommerce_after_shop_loop', array( $this, 'wppp_dropdown' ) );
|
297 |
+
elseif ( $this->settings['location'] == 'topbottom' ):
|
298 |
+
add_action( 'woocommerce_before_shop_loop', array( $this, 'wppp_dropdown' ) );
|
299 |
+
add_action( 'woocommerce_after_shop_loop', array( $this, 'wppp_dropdown' ) );
|
300 |
+
endif;
|
301 |
+
|
|
|
|
|
|
|
302 |
}
|
303 |
+
|
304 |
+
|
305 |
+
/**
|
306 |
+
* Products per page dropdown.
|
307 |
+
*
|
308 |
+
* @since 1.0.0
|
309 |
+
* @deprecated 1.1.0 Use wppp_dropdown() instead.
|
310 |
+
*
|
311 |
+
* @return void.
|
312 |
+
*/
|
313 |
public function wppp_dropdown_object() {
|
314 |
+
$this->wppp_dropdown();
|
315 |
+
}
|
316 |
+
|
317 |
+
|
318 |
+
/**
|
319 |
+
* Include dropdown.
|
320 |
+
*
|
321 |
+
* Include dropdown class and create an instance.
|
322 |
+
*
|
323 |
+
* @since 1.0.0
|
324 |
+
*
|
325 |
+
* @return void.
|
326 |
+
*/
|
327 |
+
public function wppp_dropdown() {
|
328 |
+
|
329 |
+
/**
|
330 |
+
* Products per page dropdown
|
331 |
+
*/
|
332 |
+
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wppp-dropdown.php';
|
333 |
new wppp_dropdown();
|
334 |
+
|
335 |
}
|
336 |
+
|
337 |
+
|
338 |
+
/**
|
339 |
+
* Initilize session.
|
340 |
+
*
|
341 |
+
* Set an initial session for WC 2.1.X users. Cookies are set automatically prior 2.1.X.
|
342 |
+
*
|
343 |
+
* @since 1.0.0
|
344 |
+
*
|
345 |
+
* @global object $woocommerce WooCommerce global object.
|
346 |
+
*
|
347 |
+
* @return void.
|
348 |
+
*/
|
349 |
+
public function wppp_set_customer_session() {
|
350 |
+
|
351 |
+
global $woocommerce;
|
352 |
|
353 |
+
if ( $woocommerce->version > '2.1' ) :
|
354 |
+
$woocommerce->session->set_customer_session_cookie( true );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
endif;
|
356 |
+
|
|
|
|
|
357 |
}
|
358 |
+
|
359 |
+
|
360 |
+
/**
|
361 |
+
* Set session.
|
362 |
+
*
|
363 |
+
* Set products per page in session.
|
364 |
+
*
|
365 |
+
* @since 1.1.0
|
366 |
+
*
|
367 |
+
* @global object $woocommerce WooCommerce global object.
|
368 |
+
*
|
369 |
+
* @return void.
|
370 |
+
*/
|
371 |
+
public function wppp_submit_check() {
|
372 |
+
|
373 |
+
global $woocommerce;
|
374 |
|
375 |
+
if ( isset( $_POST['wppp_ppp'] ) ) :
|
376 |
+
$woocommerce->session->set( 'products_per_page', $_POST['wppp_ppp'] );
|
377 |
+
elseif ( isset( $_GET['wppp_ppp'] ) ) :
|
378 |
+
$woocommerce->session->set( 'products_per_page', $_GET['wppp_ppp'] );
|
379 |
+
endif;
|
380 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
}
|
382 |
+
|
383 |
|
384 |
}
|
|
|
385 |
|
386 |
+
global $wppp;
|
387 |
+
$wppp = new woocommerce_products_per_page();
|
388 |
+
$wppp->wppp_shop_hooks();
|
|