Mukhyyar
Mukhyyar

Reputation: 107

Custom Price for a specific product in Woocommerce

In Woocommerce, I would like to apply custom price for a specific product.

This is my actual code:

add_action('woocommerce_get_price','change_price_regular_member', 10, 2);
function change_price_regular_member($price, $productd){
    return '1000';
}

Any help on this is appreciated.

Upvotes: 2

Views: 1892

Answers (2)

LoicTheAztec
LoicTheAztec

Reputation: 253901

The hook woocommerce_get_price is outdated and deprecated in Woocommerce 3 (and it was a filter hook but NOT an action hook). It has been replaced by woocommerce_product_get_price.

So instead try this (where you will define your targeted Product ID in this hooked function):

add_filter( 'woocommerce_product_get_price','change_price_regular_member', 10, 2 );
function change_price_regular_member( $price, $product ){
    // HERE below define your product ID
    $targeted_product_id = 37;

    if( $product->get_id() == $targeted_product_id )
        $price = '1000';

    return $price;
}

This code goes on function.php file of your active child theme (or theme). Tested and works.

Upvotes: 1

Vel
Vel

Reputation: 9331

Try this code. just replace id of product 3030

add_action('woocommerce_get_price','change_price_regular_member', 10, 2);
function change_price_regular_member($price, $productd){
    if($productd->id==3030){
        $price= 1000;
    }
    return $price;
}

Upvotes: 0

Related Questions