Follow these steps to hide the CPB’s addon products on the shop page.
- Download the attached file and override in the mentioned path
wp-content/plugins/custom-product-boxes/admin/settings/class-cpb-settings.php
- Go to Custom Product Boxes > Settings and Enable Hide add-on’s from shop option and then Enter the password. It will change the status of the product from published to protected.
- After overriding the file, add the following code in your function.php of child_theme/main_theme.
// Filter to hide protected posts
function cpb_exclude_protected($where) {
global $wpdb;
return $where .= " AND {$wpdb->posts}.post_password = '' ";
}
// Decide where to display them
function cpb_exclude_protected_action($query) {
if ( 'product' != $_REQUEST['post_type'] ) {
add_filter( 'posts_where', 'cpb_exclude_protected' );
}
}
// Action to queue the filter at the right time
add_action('pre_get_posts', 'cpb_exclude_protected_action');
- The above code will hide the protected product from the Shop page.