2

I'm trying to build custom export column in WP All Export but I can not get what I'm trying to achieve. I need column 'For Payment', where I need to place actual order total in case the payment method is COD. Otherwise it should return 0 (required by couriers). I tried to modify code below but it doesn't work.

<?php
function cod_payment( $order_id ) {
    $total = get_total();
    $method = get_payment_method();
    if($method == "cod") {
        return $total;
    } else {
        return "0";
    }
}
?>

Edit Export Field dialogue in WP All Export

montrealist
  • 5,593
  • 12
  • 46
  • 68
Karnak
  • 21
  • 2
  • 7
  • 21

2 Answers2

2

You can do something like this. select Custom export field add the function call in the text area

[cod_payment({Payment Method},{Order Total})]

and finaly the PHP to the function editor (make sure to save it)

<?php
function cod_payment( $method, $total ) {

    if($method == "cod") {
        return $total;
    } else {
        return "0";
    }
}
?>

Keep in mind the method name may not be correct.

Screenshot

Jasper B
  • 851
  • 4
  • 13
  • Hm, I tested this and I must have payment method title column included. Is there a maybe a way to avoid it? I just need "for payment" column – Karnak Apr 08 '21 at 16:27
  • hi sorry the screenshot is incorrect I changed the code to have the correct fields, the payment method is located under "Other" – Jasper B Apr 09 '21 at 13:55
0

I need column 'For Payment'

So the value of the Column name text field should be "For Payment", not "Order Total".

Also, in order for the PHP function to be called, you need to specify its name in the text field between <?php and ($value); ?>. It should be "cod_payment", not "cliente_jr".

Finally, why isn't the $order_id being used inside the function? I assume you need it to fetch the total and the payment method, possibly something like this:

<?php
function cod_payment( $order_id ) {
    $total = get_total( $order_id );
    $method = get_payment_method( $order_id );
    if($method == "cod") {
        return $total;
    } else {
        return "0";
    }
}
?>
montrealist
  • 5,593
  • 12
  • 46
  • 68
  • Thank you for your answer! I did everything like you but I get an error "An unknown error occured"... Can not figure out what exactly is wrong. I'm dealing with this plugin first time :/ – Karnak Apr 05 '21 at 16:55
  • Try turning on debugging to see if there are errors in the `wp-content/debug.log` file: https://wordpress.org/support/article/debugging-in-wordpress/ – montrealist Apr 06 '21 at 03:24