Skip to content

Commit

Permalink
Performance tweak and add featured products show/hide capability
Browse files Browse the repository at this point in the history
  • Loading branch information
roykho committed Jun 2, 2016
1 parent 092eb87 commit c6aef6a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
49 changes: 43 additions & 6 deletions includes/class-wc-geolocation-based-products-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ public function __construct( WC_Geolocation_Based_Products_Geolocate $geolocate
// hide products from menu
add_filter( 'wp_nav_menu_objects', array( $this, 'hide_products_from_menu' ), 10, 2 );

// hide products from shortcodes
add_filter( 'woocommerce_shortcode_products_query', array( $this, 'hide_shortcode_products' ) );

return true;
}

/**
* public access to instance object
*
* @since 1.1.1
* @version 1.1.1
* @return bool
*/
public function get_instance() {
Expand All @@ -67,6 +71,7 @@ public function get_instance() {
*
* @access public
* @since 1.0.0
* @version 1.0.0
* @return string $user_country
*/
public function get_user_country() {
Expand All @@ -80,6 +85,7 @@ public function get_user_country() {
*
* @access public
* @since 1.1.0
* @version 1.1.0
* @return string $user_region
*/
public function get_user_region() {
Expand All @@ -93,6 +99,7 @@ public function get_user_region() {
*
* @access public
* @since 1.1.0
* @version 1.1.0
* @return string $user_city
*/
public function get_user_city() {
Expand Down Expand Up @@ -216,6 +223,7 @@ public function location_matched( $country, $region, $city ) {
*
* @access public
* @since 1.1.0
* @version 1.1.0
* @param string $saved_country | saved country setting to match
* @return bool
*/
Expand All @@ -234,6 +242,7 @@ public function country_is_matched( $saved_country = null ) {
*
* @access public
* @since 1.1.0
* @version 1.1.0
* @param string $saved_region | saved region setting to match
* @return bool
*/
Expand Down Expand Up @@ -270,6 +279,7 @@ public function city_is_matched( $saved_city = null ) {
*
* @access public
* @since 1.0.0
* @version 1.0.0
* @param object $q | the main query object
* @return bool
*/
Expand Down Expand Up @@ -314,6 +324,7 @@ public function filter_query( $q ) {
*
* @access public
* @since 1.1.4
* @version 1.1.4
* @return array $ids
*/
public function get_product_ids_from_excluded_cats() {
Expand Down Expand Up @@ -345,7 +356,8 @@ public function get_product_ids_from_excluded_cats() {
* Hide categories from category view
*
* @access public
* @since 1.0.0
* @since 1.0.0
* @version 1.0.0
* @return bool
*/
public function hide_from_categories_view( $args ) {
Expand All @@ -364,6 +376,7 @@ public function hide_from_categories_view( $args ) {
*
* @access public
* @since 1.1.4
* @version 1.1.4
* @return array $terms
*/
public function update_category_count( $terms ) {
Expand Down Expand Up @@ -415,7 +428,8 @@ public function update_category_count( $terms ) {
* Hide products from products widget
*
* @access public
* @since 1.0.0
* @since 1.0.0
* @version 1.0.0
* @param array $args
* @return array $args
*/
Expand Down Expand Up @@ -463,7 +477,7 @@ public function hide_related_products( $args ) {
* Hide upsell products
*
* @access public
* @since 1.3.2
* @since 1.3.2
* @version 1.3.2
* @param array $ids
* @return array $ids
Expand All @@ -488,7 +502,7 @@ public function hide_upsell_products( $ids ) {
* Hide crosssell products
*
* @access public
* @since 1.3.2
* @since 1.3.2
* @version 1.3.2
* @param array $ids
* @return array $ids
Expand All @@ -509,23 +523,46 @@ public function hide_crosssell_products( $ids ) {
return $ids;
}

/**
* Hide shortcode products
*
* @access public
* @since 1.5.1
* @version 1.5.1
* @param array $args
* @return array $args
*/
public function hide_shortcode_products( $args ) {
if ( $this->matches ) {
$product_ids = array_filter( array_map( 'absint', $this->matches['products'] ) );

$excluded_ids = array_unique( array_merge( $product_ids, $this->get_product_ids_from_excluded_cats() ) );

$args['post__not_in'] = $excluded_ids;
}

return $args;
}

/**
* Hide products from menu
*
* @access public
* @since 1.1.4
* @version 1.5.1
* @param array $atts HTML attributes
* @param array $args config of the nav item
* @return array $atts
*/
public function hide_products_from_menu( $items, $args ) {
if ( $this->matches ) {
$product_ids = array_filter( array_map( 'absint', $this->matches['products'] ) );
$product_ids = array_filter( array_map( 'absint', $this->matches['products'] ) );
$products_excluded_cats = $this->get_product_ids_from_excluded_cats();

foreach( $items as $key => $item ) {
if ( in_array( (int) $item->object_id, $product_ids )
|| in_array( (int) $item->object_id, $this->matches['product_cats'] )
|| in_array( (int) $item->object_id, $this->get_product_ids_from_excluded_cats() )
|| in_array( (int) $item->object_id, $products_excluded_cats )
) {
unset( $items[ $key ] );
}
Expand Down
11 changes: 8 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
WordPress requires at least: 3.9.1
Tested up to: 4.5.1
WooCommerce requires at least: 2.5.0
Stable tag: 1.5.0
Stable tag: 1.5.1
Author URI: http://royho.me
Plugin URI: https://wordpress.org/plugins/woocommerce-geolocation-based-products/
License: GPLv3
Expand Down Expand Up @@ -72,11 +72,16 @@ You can post a GitHub issue here https://github.com/roykho/woocommerce-geolocati

== Upgrade Notice ==

= 1.5.0 =
* Add - Ability to show and hide products and categories by location. Since this is a major update, rules will be emptied. Please reapply all rules.
= 1.5.1 =
* Tweak - Performance.
* Add - Show/hide ability when using featured products shortcode.

== Changelog ==

= 1.5.1 | 06-01-2016 =
* Tweak - Performance.
* Add - Show/hide ability when using featured products shortcode.

= 1.5.0 | 05-02-2016 =
* Add - Ability to show and hide products and categories by location

Expand Down
4 changes: 2 additions & 2 deletions woocommerce-geolocation-based-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Geolocation Based Products
* Plugin URI: https://wordpress.org/plugins/woocommerce-geolocation-based-products/
* Description: A WooCommerce plugin/extension that adds ability for your store to hide products based on visitors geolocation.
* Version: 1.5.0
* Version: 1.5.1
* Author: Roy Ho
* Author URI: http://royho.me
* Text Domain: woocommerce-geolocation-based-products
Expand Down Expand Up @@ -59,7 +59,7 @@ class WC_Geolocation_Based_Products {
public function __construct() {
self::$_this = $this;

define( 'WC_GEOLOCATION_BASED_PRODUCTS_VERSION', '1.5.0' );
define( 'WC_GEOLOCATION_BASED_PRODUCTS_VERSION', '1.5.1' );

add_action( 'init', array( $this, 'load_plugin_textdomain' ) );

Expand Down

0 comments on commit c6aef6a

Please sign in to comment.