[Suggestion] Stick to defined numbers per page
-
Hello,
I’ve noticed visitor could manipulate things in order to modify the number of products per page to any they would like to.
As a webmaster, I think it is important to manage this on my side, to offer the best experience, i.e. I’d like the visitor to select and use only predefined numbers of products per page.
So I modified (for me)loop_shop_per_page
and
products_per_page_action
as follow and suggest you those modifications:
loop_shop_per_page :public function loop_shop_per_page( $per_page ) { if ( isset( $_REQUEST['wppp_ppp'] ) ) { $per_page = intval( $_REQUEST['wppp_ppp'] ); } elseif ( isset( $_REQUEST['ppp'] ) ) { // Set the products per page options (e.g. 4, 8, 12) $per_page = intval( $_REQUEST['ppp'] ); } elseif ( isset( $_COOKIE['woocommerce_products_per_page'] ) ) { $per_page = $_COOKIE['woocommerce_products_per_page']; }; // MR - Check if value sent is an allowed value... Otherwise back to default! // else $per_page = intval( get_option( 'wppp_default_ppp', '12' ) ); $products_per_page_options = array_values( explode( ' ', apply_filters( 'wppp_products_per_page', get_option( 'wppp_dropdown_options' ) ) ) ); if (! in_array($per_page, $products_per_page_options)) $per_page = intval( get_option( 'wppp_default_ppp', '12' ) ); return $per_page; }
products_per_page_action :
public function products_per_page_action() { // MR - Check against 'loop_shop_per_page' to write correct value if ( isset( $_REQUEST['wppp_ppp'] ) ) : wc_setcookie( 'woocommerce_products_per_page', $this->loop_shop_per_page( ( intval($_REQUEST['wppp_ppp']) ) ), time() + DAY_IN_SECONDS * 2, apply_filters( 'wc_session_use_secure_cookie', false ) ); elseif ( isset( $_REQUEST['ppp'] ) ) : wc_setcookie( 'woocommerce_products_per_page', $this->loop_shop_per_page( ( intval($_REQUEST['ppp']) ) ), time() + DAY_IN_SECONDS * 2, apply_filters( 'wc_session_use_secure_cookie', false ) ); endif; }
Happy to share ??
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘[Suggestion] Stick to defined numbers per page’ is closed to new replies.