- This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I am setting up an online store for an art supply company using WooCommerce. I need to be able to offer a discounted price (for all items) to teachers.
So basically when a teacher logs in to their account they will see the discounted prices and when a normal customer logs in to their account they will see the normal prices.
The two issues I see are:
The discounted price is not as simple as a set percentage off each item so each item will need a specific normal price and teacher price.
Any ideas?
Thanks!!!
You can use woocommerce_get_price
hook and do any necessary logic. So something like:
// Untested Code
add_filter('woocommerce_get_price', 'teacher_custom_price', 10, 2);
function teacher_custom_price($price, $product)
{
// if guest, return current price
if ( !is_user_logged_in() ) return $price;
// check for user role
$user = wp_get_current_user();
if ( in_array( "teacher", (array) $user->roles ) {
$user_discount = get_user_meta($user->ID, 'discount', true);
return $price * $user_discount;
}
}
If you wish to add custom discounts per user, you can attach meta data to the user and enter their discount value there. Then just access it within teacher_custom_price
function and do your maths. See: