Solution:
Try this code:
add_filter( 'woocommerce_product_variation_get_price', 'custom_price', 10, 2 );
add_filter( 'woocommerce_product_get_price', 'custom_price', 10, 2 );
function custom_price( $price, $product ) {
if ( ! is_user_logged_in() ) {
return $price;
}
if ( has_role( 'hintaluokka-5' ) ) {
$price *= 0.95;
} elseif ( has_role( 'hintaluokka-12' ) ) {
$price *= 0.88;
} elseif ( has_role( 'hintaluokka-15' ) ) {
$price *= 0.85;
} elseif ( has_role( 'hintaluokka-22' ) ) {
if ( has_term( 'kastikkeet', 'product_cat', $product->ID ) ) {
$price *= 0.78;
} else {
$price *= 0.9;
}
}
return $price;
}
function has_role( $role = '', $user_id = null ) {
if ( is_numeric( $user_id ) ) {
$user = get_user_by( 'id', $user_id );
} else {
$user = wp_get_current_user();
}
if ( empty( $user ) ) {
return false;
}
return in_array( $role, $user->roles, true );
}
I don’t see a huge problem here. There is just one hook which is no longer used (deprecated).
Post the error message in case this don’t helps.