Skip to content

Instantly share code, notes, and snippets.

@maxkostinevich
Created September 19, 2016 03:24
Show Gist options
  • Save maxkostinevich/e57a1ee0768b47bf2716e8e0f4347a7d to your computer and use it in GitHub Desktop.
Save maxkostinevich/e57a1ee0768b47bf2716e8e0f4347a7d to your computer and use it in GitHub Desktop.
WooCommerce - How to hide product price and attributes for non-authorized users
<?php
// Hide WooCommerce product price, attributes and variations for non-logged-in users
function my_theme_hide_price_not_authorized() {
if ( !is_user_logged_in() ) {
// Hide price
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// Hide variations
add_filter( 'woocommerce_variation_is_active', 'my_theme_disable_variation', 10, 2 );
// Hide Add-to-cart button
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
// Hide attributes
add_filter( 'woocommerce_attribute', 'my_theme_hide_attribute');
}
}
add_action('init', 'my_theme_hide_price_not_authorized');
// Hide product variations
function my_theme_disable_variation() {
return false;
}
// Hide product attributes
function my_theme_hide_attribute() {
return '';
}
@marycor
Copy link

marycor commented Jun 3, 2020

Hi I am trying to hide specific attributes from non authorized users on a woo commerce site, is this possible?
I have no experience with code. Thanks

@marycor
Copy link

marycor commented Jun 3, 2020

Price is hidden via the set up of the product

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment