Skip to content

Instantly share code, notes, and snippets.

@woogist
Created February 13, 2014 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woogist/8983691 to your computer and use it in GitHub Desktop.
Save woogist/8983691 to your computer and use it in GitHub Desktop.
Add the following to your theme's functions.php to show product documents only for logged in users. Note that this is a very simple example, and could be expanded upon to show documents only for a particular user role, only for particular products, anything! http://www.woothemes.com/products/product-documents/
<?php
add_filter( 'wc_product_documents_get_sections', 'show_documents_only_for_logged_in_users', 10, 3 );
/**
* Don't return document sections unless there is a logged in user.
*
* @param array $sections array of sections
* @param WC_Product_Documents_Collection $collection the collection object
* @param boolean $include_empty whether to include empty sections in the result
* @return array sections for display
*/
function show_documents_only_for_logged_in_users( $sections, $collection, $include_empty ) {
// this check can be made as specific (by user role, etc) as desired
if ( ! get_current_user_id() ) {
return array();
}
return $sections;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment