Skip to content

Instantly share code, notes, and snippets.

@woogist
Last active August 22, 2017 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woogist/9920046 to your computer and use it in GitHub Desktop.
Save woogist/9920046 to your computer and use it in GitHub Desktop.
Show Product Documents to Logged In Users Only - add everything after the <?php tag to the bottom of your theme's functions.php file.
<?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