WooCommerce Cart - Dynamic Price variable pass into custom price hook

后端 未结 2 852
难免孤独
难免孤独 2021-01-14 11:26

I am getting the dynamic custom price in a variable that I want to pass to the hooked function in woocommerce_before_calculate_totals hook in cart. But it i

2条回答
  •  被撕碎了的回忆
    2021-01-14 12:11

    To add Price in your woocommerce cart before calculate total -

     add_action( 'woocommerce_before_calculate_totals', 'add_custom_total_price');
    
      function add_custom_total_price($cart_object) {
         global $woocommerce,$add,$custom_price; 
         $add=200;//Dynamic Price variable
         $custom_price =$add;//Dynamic Price variable pass to custom price
        foreach ( $cart_object->cart_contents as $key => $value ) {
           $value['data']->price = $custom_price;
        }
     } 
    

提交回复
热议问题