Custom price formula doesn’t affect subscriptions price
-
At single product page the customers can choose from a counter box the number of terabytes they want for the product they want to purchase. I take that number and with a custom function I add it at the products price. The price is saved correct at the tables of wordpress but at the subscription panel at /my-account/my-subscription/ the price still remains the same.
For example a customer buys a Product A with basic price 54 and choose 2 terabytes for that product, the price with the functions I added becomes 56 but at Subscriptions panel still remains 54.
Below is my code. Any suggestions would be appreciated. Thank you.add_filter( 'woocommerce_add_cart_item_data', 'add_cart_item_data', 10, 3 ); function add_cart_item_data( $cart_item_data, $product_id, $variation_id ) { // get product id & price $product = wc_get_product( $product_id ); $price = $product->get_price(); // extra pack checkbox $tera = $_POST['number-1620393141673']; $cart_item_data['new_price'] = $price + $tera; return $cart_item_data; }
add_action( 'woocommerce_before_calculate_totals', 'before_calculate_totals', 10, 1 ); function before_calculate_totals( $cart_obj ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { return; } // Iterate through each cart item foreach( $cart_obj->get_cart() as $key=>$value ) { if( isset( $value['new_price'] ) ) { $price = $value['new_price']; $value['data']->set_price( ( $price ) ); } } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom price formula doesn’t affect subscriptions price’ is closed to new replies.