1

This code works perfectly in product. But in cart, it shows 0. I checked the code and it seems that this line doesn't function:

 get_field('get_price', $product->ID)

I use ACF plug-in. And I try to check - in cart $product is empty. Can you help me, how can I get "product id" from cart use "woocommerce_product_get_price"?

This topic is different from link because i use hook to change price. And code, which talk in this link no function inside hook.

Here is code

add_filter('woocommerce_product_variation_get_regular_price', 'my_custom_price', 99);
    add_filter('woocommerce_product_variation_get_price', 'my_custom_price', 99);
    add_filter('woocommerce_product_get_price', array( $this, 'my_custom_price'), 99);
    add_filter('woocommerce_product_get_regular_price', array( $this, 'my_custom_price'), 99);

    function my_custom_price( $price ) {
        global $post,$product;


        if (get_field('get_price', $product->ID)==1){
            // Delete product cached price  (if needed)
            wc_delete_product_transients($post->ID);

            //get price (autoupdate by cron every day)
            $get_course = file_get_contents(__DIR__.'/btc_price2.inc');     
            $get_course=1/$get_course;
            //change value      
            $nacenka=($price*$get_course)/100;
            $dop_nacenka=(get_field('add_more', $product->ID)*$get_course)/100;

            $price=($get_course+$nacenka+$dop_nacenka);
        }

0 Answers0