Last active
July 4, 2018 10:33
-
-
Save pelmered/a9e725cb0b712aeac24a to your computer and use it in GitHub Desktop.
Override price based on group/role of logged in user
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
add_filter('woocommerce_get_sale_price', 'my_custom_price', 99, 2); | |
add_filter('woocommerce_get_price', 'my_custom_price', 99, 2); | |
function my_custom_price( $price, $product ) | |
{ | |
//your logic for calculating the new price here | |
//Half price for VIP-customers | |
if( in_array('vip', get_userdata(get_current_user_id())->roles ) | |
{ | |
$price = $product->get_regular_price() / 2; | |
} | |
//Return the new price (this is the price that will be used everywhere in the store) | |
return $price; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment