Skip to content

Instantly share code, notes, and snippets.

@pelmered
Last active July 4, 2018 10:33
Show Gist options
  • Save pelmered/a9e725cb0b712aeac24a to your computer and use it in GitHub Desktop.
Save pelmered/a9e725cb0b712aeac24a to your computer and use it in GitHub Desktop.
Override price based on group/role of logged in user
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