0
votes

From our funtions.php with an add_filter function we try to increase the price of products automatically, if the product has certain attributes choosen with an specific name: Chrom -> +2.95 and Titan -> + 5,95 The price has to be changed everyhwer: inside the cart. the order, the product details page, the overview page.

Do we need to overwrite the price.php? If so - no problem. Or is it enough to place code in the functions.php to achive that?

As we are not very good in coding, we did some research in the woocommerce docs but were not able to come up with any results that would make sense to post here.

Thanks for help

1
Your question is not clear enough: is it for simple products, variable products? The product attribute is it a normal product attribute or a product attribute used for variations. What is your main product attribute name? Try to clarify your question please, as it's unclear and not useful for other readers actually.LoicTheAztec

1 Answers

0
votes

You can do it by code, but since it seems that it's a one time change you can use a bulk price editor plugin .

Or try this code:

    add_filter( 'woocommerce_get_price', 'calculate_price_by_material', 9999, 2 );
function calculate_price_by_material($price, $product){
    $materials = explode(',',$product->get_attribute('Material'));
    foreach ($materials as $material){
        if (($material == 'Chrom') || ($material == 'Titan')){
            $price *= 2.5;
        }
    }
    return $price;
}