Guest User

Untitled

a guest
Jul 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. add_action( 'woocommerce_before_calculate_totals', 'extra_price_add_custom_price', 9999, 1 );
  2. function extra_price_add_custom_price( $cart ) {
  3. if ( is_admin() && !defined('DOING_AJAX') )
  4. return;
  5.  
  6. foreach ( $cart->get_cart() as $cart_item ) {
  7. echo $cart_item['data']->price; // this gives the price that i want but
  8.  
  9. if( isset($cart_item['custom_data']['new_price']) ){
  10. $cart_item['data']->set_price( floatval($cart_item['custom_data']['new_price']) ); // here price is not updated
  11. }
  12. }
  13. }
Add Comment
Please, Sign In to add comment