|
/** |
|
* @Title: WooCommerce Display Price and Add to Cart button for specific user role only from Shop and Single Product pages |
|
* @Author: Mina Pansuriya |
|
* @Website: http://minapansuriya.com |
|
*/ |
|
if(is_user_logged_in() ) |
|
{ |
|
$current_user = wp_get_current_user(); |
|
foreach ( $current_user->roles as $role ) |
|
{ |
|
if($role != "Customer" || $role != "Admin") |
|
{ |
|
// If user role is Customer or Admin, Add to Cart button and Price will display on both Single and Shop/Category Pages |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
pbs_woo_remove_add_to_cart_and_price(); |
|
} |
|
|
|
|
|
function pbs_woo_remove_add_to_cart_and_price() |
|
{ |
|
// Remove Add to cart from Single Product Page |
|
remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 ); |
|
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 ); |
|
remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 ); |
|
remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 ); |
|
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 ); |
|
|
|
// Remove Add to cart from Single Product Page |
|
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); |
|
|
|
// Remove Add to Cart from Shop/Category Pages (Limitation: This code will remove "Select Option" from Grouped and Variable product also |
|
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); |
|
|
|
// Remove Price from Shop/Category Pages |
|
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); |
|
} |