Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda