Plugin Author
Kento
(@proaktion)
Hi,
If you restrict a product to a certain group, it would only be visible to members of that group who are logged in. Can you please give an example of a product which is restricted but shows up on your sitemap?
Also you can try out https://github.com/itthinx/groups-sandbox – I’ve created it a few days ago based on a question from another user and it might come in handy for your checks, too. Download the zip file and install it. You can then place shortcodes like this on a page … this example assumes you have a group “Test” and are using it to restrict some products:
[groups_sandbox_posts group="Test" post_type="product"]
Does the above help?
Plugin Author
Kento
(@proaktion)
PS You’ll find more examples and details on the shortcode also on https://github.com/itthinx/groups-sandbox
Hi Kento, I use yoast seo for my sitemap.
I have gotten a filter from them, do do some checking.
add_filter( 'wpseo_sitemap_entry', array( $this, 'sitemap_exclude_product' ), 10, 3 );
// HIDE INVISIBLE PRODUCTS FROM SITEMAP
function sitemap_exclude_product( $url, $type, $post ) {
$post_type = get_post_type($post->ID);
// ONLY DO FOR PRODUCTS
if ( $post_type=='product' ){
// CHECK IF PRODUCT ONLY VISIBLE FOR GROUPS
if( class_exists( 'Groups_Cache') ){
$product = new WC_Product( $post );
$visible = $product->is_visible();
$product_visible = intval(my_woocommerce_product_is_visible( $visible, $post->ID ));
if($product_visible==0){
return false;
}
}
}
// NEVER SHOW PRODUCT CATEGORY ZAKELIJK
if($post->slug=='zakelijk'){
return false;
}
return $url;
}
// HELPER FUNCTION TO CHECK VISIBILITY OF PRODUCT
function my_woocommerce_product_is_visible ( $visible, $product_id ) {
if ( $visible ) {
$visible = Groups_Post_Access::user_can_read_post( $product_id );
}
return $visible;
}
This solved my problems.
-
This reply was modified 8 years, 8 months ago by
darkallman.
-
This reply was modified 8 years, 8 months ago by
darkallman.
Plugin Author
Kento
(@proaktion)
Looks good, thanks for sharing your solution 🙂