Skip to content

Commit

Permalink
fixed crosssell, related and upsell products were not hiding closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
roykho committed Sep 13, 2015
1 parent eec5fe5 commit 28be3b7
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 16 deletions.
83 changes: 83 additions & 0 deletions includes/class-wc-geolocation-based-products-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public function __construct() {
// hide from products widget
add_filter( 'woocommerce_products_widget_query_args', array( $this, 'hide_from_products_widget' ) );

// hide related products
add_filter( 'woocommerce_related_products_args', array( $this, 'hide_related_products' ) );

// hide upsell products
add_filter( 'woocommerce_product_upsell_ids', array( $this, 'hide_upsell_products' ) );

// hide crossell products
add_filter( 'woocommerce_product_crosssell_ids', array( $this, 'hide_crosssell_products' ) );

// hide products from menu
add_filter( 'wp_nav_menu_objects', array( $this, 'hide_products_from_menu' ), 10, 2 );

Expand Down Expand Up @@ -416,6 +425,80 @@ public function hide_from_products_widget( $args ) {
return $args;
}

/**
* Hide related products
*
* @access public
* @since 1.3.2
* @version 1.3.2
* @param array $args
* @return array $args
*/
public function hide_related_products( $args ) {
if ( $this->exclusion ) {
$excluded_ids = array_unique( array_merge( $this->exclusion['products'], $this->get_product_ids_from_excluded_cats() ) );

foreach( $args['post__in'] as $k => $id ) {
if ( in_array( (int) $id, $excluded_ids ) ) {
unset( $args['post__in'][ $k ] );
}
}

// set a non existing id so it won't display all products when empty
if ( empty( $args['post__in'] ) ) {
$args['post__in'] = array( 0 );
}
}

return $args;
}

/**
* Hide upsell products
*
* @access public
* @since 1.3.2
* @version 1.3.2
* @param array $ids
* @return array $ids
*/
public function hide_upsell_products( $ids ) {
if ( $this->exclusion ) {
$excluded_ids = array_unique( array_merge( $this->exclusion['products'], $this->get_product_ids_from_excluded_cats() ) );

foreach( $ids as $k => $id ) {
if ( in_array( (int) $id, $excluded_ids ) ) {
unset( $ids[ $k ] );
}
}
}

return $ids;
}

/**
* Hide crosssell products
*
* @access public
* @since 1.3.2
* @version 1.3.2
* @param array $ids
* @return array $ids
*/
public function hide_crosssell_products( $ids ) {
if ( $this->exclusion ) {
$excluded_ids = array_unique( array_merge( $this->exclusion['products'], $this->get_product_ids_from_excluded_cats() ) );

foreach( $ids as $k => $id ) {
if ( in_array( (int) $id, $excluded_ids ) ) {
unset( $ids[ $k ] );
}
}
}

return $ids;
}

/**
* Hide products from menu
*
Expand Down
8 changes: 7 additions & 1 deletion 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.2
WooCommerce requires at least: 2.1.12
Stable tag: 1.3.1
Stable tag: 1.3.2
Author URI: http://royho.me
Plugin URI: https://wordpress.org/plugins/woocommerce-geolocation-based-products/
License: GPLv3
Expand Down Expand Up @@ -54,12 +54,18 @@ This plugin utilizes the IP address of the visitor to obtain location informatio

== Upgrade Notice ==

= 1.3.2 =
* Fixed - Related, crosssell and upsell products were not hiding

= 1.3.1 =
* Fixed - Suppress error when geoip API returning an error at times
* Fixed - Category widget count sometimes displays a warning when debug is on

== Changelog ==

= 1.3.2 | 09-13-2015 =
* Fixed - Related, crosssell and upsell products were not hiding

= 1.3.1 | 07-11-2015 =
* Fixed - Suppress error when geoip API returning an error at times
* Fixed - Category widget count sometimes displays a warning when debug is on
Expand Down
29 changes: 14 additions & 15 deletions woocommerce-geolocation-based-products.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?php
/*
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.3.1
Author: Roy Ho
Author URI: http://royho.me
Copyright: (c) 2014 Roy Ho
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
/**
* 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.3.2
* Author: Roy Ho
* Author URI: http://royho.me
* Text Domain: woocommerce-geolocation-based-products
* Domain Path: /languages
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
Expand All @@ -28,7 +27,7 @@
class WC_Geolocation_Based_Products {
private static $_this;

const WC_GEOLOCATION_BASED_PRODUCTS_VERSION = '1.3.1';
const WC_GEOLOCATION_BASED_PRODUCTS_VERSION = '1.3.2';

/**
* init
Expand Down

0 comments on commit 28be3b7

Please sign in to comment.