• Resolved xfolder

    (@xfolder)


    Hello!
    How to export total amount only for orders with cash on delivery?

    Thanks

    Example:
    if no COD field “COD Total Amount” -> 0
    if COD field “COD Total Amount” -> Order Total Amount

    • This topic was modified 8 years, 6 months ago by xfolder.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello,

    Could you try this code ?

    // set total =0, if payment <> COD
    add_filter('woe_get_order_value_order_total', function ($value, $order, $item, $product) {
     if( $order->payment_method != "cod") 
      $value = 0;
     return $value;
    }, 10, 4);

    thanks, Alex

    Thread Starter xfolder

    (@xfolder)

    Sorry, I think that is not for me.
    I need a meta_key like “COD value” for exporting in csv file like this:
    “name”, “address”, “total order value”, “cod”
    “Mirko Salvati”, “via Atzori 55”, “14.99”, “0” <— This is order without COD
    “Francesco Salvati”, “via Atzori 55”, “14.99”, “14.99” <— This order is with COD

    Thread Starter xfolder

    (@xfolder)

    Meanwhile I tried your code but It return a HTTP ERROR 500..

    Plugin Author algol.plus

    (@algolplus)

    Here is updated code.
    Please, use this plugin to add it https://ww.wp.xz.cn/plugins/code-snippets/

    // add new order field
    add_filter('woe_get_order_fields', function ($fields) {
      $fields['cod_amount'] = array( 'label' => 'COD Total Amount', 'colname' => 'COD Total Amount', 'checked' => 1 );
      return $fields;
    });
    // set value , if payment == COD
    add_filter('woe_get_order_value_cod_amount', function ($value, $order, $fieldname) {
      if( $order->payment_method == "cod") 
        $value = $order->get_total();
      else 
        $value = 0;
      return $value;
    }, 10, 3);
    • This reply was modified 8 years, 6 months ago by algol.plus.
    Thread Starter xfolder

    (@xfolder)

    Thanks!

    Plugin Author algol.plus

    (@algolplus)

    you’re welcome.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Total amount only for COD’ is closed to new replies.