Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
Change Woocommerce variable product price, based on category and user role not working

Title says it all.

Bellow code works as it should, for simple products. But I cannot figure out, why it has no influence on Variable products. I have been searching through the net for filter-hooks, and experimenting with a mix of different of bellow script. No luck so far.

add_filter( 'woocommerce_product_get_price', 'custom_price_for_category_role', 10, 2 );
add_filter( 'woocommerce_product_variation_get_price', 'custom_price_for_category_role', 10, 2 );
function custom_price_for_category_role( $price, $product ) {
    //Get all product categories for the current product
    $terms = wp_get_post_terms( $product->get_id(), 'product_cat' );
    foreach ( $terms as $term ) {
        $categories[] = $term->slug;
    }

    if ( ! empty( $categories ) && in_array( 'b2b', $categories, true ) && current_user_can('b2b') ) {
        $price = (($price * 1.25) / 3);
    }

    return $price;

}

Bonus question: What could be the reason that woocommerce_product_get_regular_price, has no effect.(also for simple products) I would like to have the code only apply to regular price, and ignore sales price.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!