Skip to content

Instantly share code, notes, and snippets.

@jjmontalban
Created May 11, 2021 10:11
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 jjmontalban/f32bcc0513866f2a439d7499fd905f8d to your computer and use it in GitHub Desktop.
Save jjmontalban/f32bcc0513866f2a439d7499fd905f8d to your computer and use it in GitHub Desktop.
Woocommerce - Change User Role for New Customers
<?php
/**
* @snippet Change User Role for New Customers - WooCommerce
* @compatible WC 4.6
* @based on https://businessbloomer.com/bloomer-armada/
*/
///////////////////////////////
// 1. Creacion de rol "Pendiente"
add_role( 'pending', __('Pendiente' ),array(
'read' => true,
)
);
// 2. Asignación del rol "Pendiente" a los nuevos usuarios
add_filter('woocommerce_new_customer_data', 'assign_custom_role', 10, 1);
function assign_custom_role($args) {
$args['role'] = 'pending';
return $args;
}
// 3. Deshabilitar precios y botón añadir al carrito a rol pendiente
add_action('after_setup_theme','user_activate_filter') ;
function user_activate_filter(){
add_filter('woocommerce_get_price_html', 'user_show_price_logged');
}
function user_show_price_logged($price){
if(current_user_can('customer') or current_user_can('editor') or current_user_can('shop_manager') or current_user_can('administrator') ){
return $price;
}
else {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
return '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment