M
M
Max99992020-04-24 23:26:50
WordPress
Max9999, 2020-04-24 23:26:50

Get added woocommerce order details?

Good day.
In the checkout cart (wordpress + woocommerce) I add a discount:

add_action('woocommerce_cart_calculate_fees' , 'add_custom_discount', 20, 1);
      function add_custom_discount( WC_Cart $cart){
        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
        $percent = WC()->session->get( 'final_discount' );
        if( $percent > 0 ){
          $cart->add_fee( __('Скидка', 'woocommerce' ) , - $percent);
        }
      }

It works, it is added... In the admin panel, in the order, you can see it, but I can’t get it programmatically. How to get it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max9999, 2020-04-25
@Max9999

I found this data in $item[data:protected][total], but protected can only be obtained from a method... Who knows how?

global $woocommerce;
$wc_order = new WC_Order(26);
$items = $wc_order->get_fees();
foreach ($items as $item) {
  // $item[data:protected][total];
  echo "<pre>";
  print_r($item);
  echo "</pre>";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question