Skip to content

Commit

Permalink
Avoid PHP notices
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomollet committed Jul 16, 2018
1 parent e965d4d commit a892115
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions inc/plugins/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,29 @@ function stormbringer_related_products_args( $args ) {

/**
* WooCommerce pre_get_posts for number of products per page, based on number of columns
* @param $query
* @param WP_Query $query
*/
function stormbringer_woocommerce_products_per_page( $query ) {

$front_page_id = get_option( 'page_on_front' );
$current_page_id = $query->get( 'page_id' );
$shop_page_id = apply_filters( 'woocommerce_get_shop_page_id' , get_option( 'woocommerce_shop_page_id' ) );
$is_static_front_page = 'page' == get_option( 'show_on_front' );

if ( $is_static_front_page && $front_page_id == $current_page_id ) {
$is_shop_page = ( $current_page_id == $shop_page_id ) ? true : false;
} else {
$is_shop_page = is_shop();
}

if(!is_admin()){
if ( (is_shop() || is_product_category() || is_product_tag() || is_product()) && $query->is_main_query() ) {
$query->set( 'posts_per_page', 3 * get_theme_mod('woocommerce_columns', 4) );
if($query->is_main_query()){
if ( $is_shop_page || is_product_category() || is_product_tag() || is_product() ) {
$query->set( 'posts_per_page', 3 * get_theme_mod('woocommerce_columns', 4) );
}
}
}

}
}
add_action( 'pre_get_posts', 'stormbringer_woocommerce_products_per_page' );

Expand Down

0 comments on commit a892115

Please sign in to comment.