Created
May 11, 2021 10:11
-
-
Save jjmontalban/f32bcc0513866f2a439d7499fd905f8d to your computer and use it in GitHub Desktop.
Woocommerce - Change User Role for New Customers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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