Advertisement
cdelphi78

Untitled

Mar 8th, 2020
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. //расчет итоговой цены товара
  2.  
  3. function ut_before_calculate_totals( $cart_obj ) {
  4.     echo '<pre>';
  5.         var_dump($cart_obj->get_cart());
  6.     echo '</pre>';
  7.  
  8.     foreach( $cart_obj->get_cart() as $key => $value ) {
  9.  
  10.         $product_total_price = ( !empty( get_post_meta( $value['data']->get_id(), '_sale_price', true) ) ) ? get_post_meta( $value['data']->get_id(), '_sale_price', true) : get_post_meta( $value['data']->get_id(), '_regular_price', true);
  11.         $volume = ( isset( $value['variation']['attribute_m-3-na-poddone'] ) ) ? $value['variation']['attribute_m-3-na-poddone'] : 1 ;
  12.         $result_price = $product_total_price * $volume ;
  13.        
  14.         $value['data']->set_price( $result_price );
  15.  
  16.     }
  17. }
  18. add_action( 'woocommerce_before_calculate_totals', 'ut_before_calculate_totals', 10, 1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement