I use WP All Export to export invoice data to my accounting program, I would need to create a "Customer" field containing the _billing_company field in case I have data or $_billing_first_name". ".$_billing_last_name in case there is no company name.
The function is as follows:
<?php
function company_conditioning($_billing_company, $_billing_first_name, $_billing_last_name) {
if(strlen($_billing_company) < 2) {
return $_billing_first_name." ".$_billing_last_name;
} else {
return $_billing_company;
}
}
?>
When I save the function, everything is OK, but when I execute the results, WP All Export gives "An unknown error occured" error
I've noticed what happens when I put more than one variable into function
For example, this function works perfectly, (If there is a company name it, shows it, and if not it shows OK)
<?php
function company_conditioning($_billing_company) {
if(strlen($_billing_company) < 2) {
return 'ok';
} else {
return $_billing_company;
}
}
?>
I need to export it in .xls (it does not work in XML)
As I indicate below, the problem is that WP All import does not handle two variables in the functions. So I find big problems when trying to export coded data.
The problem is that you have to call two fields that are in the wp_postmeta table. I tried calling $post_id and then calling the two fields with get_post, but I couldn't get it to work.
<?php
function cliente_jr( $post_id ) {
$empresa_jr = get_post( $post_id, 'billing_company', true );
$nombrefac_jr = get_post( $post_id, 'billing_first_name', true );
$apellidofac_jr = get_post( $post_id, 'billing_last_name', true );
if(strlen($empresa_jr) < 2) {
return $nombrefac_jr." ".$apellidofac_jr;
} else {
return $empresa_jr;
}
}
?>
Any ideas?
Edit. Another example If $payment_method is COD, put the value of $order_total, else put 0
I have been able to solve it IF THE CUSTOMER IS REGISTERED, the main problem is that the functions in WP ALL Export do not accept more than one variable, so the results have to be called from the function.
If the client is registered, since I can obtain the data from get_user_meta, but if the client is not registered, the billing_company field is not obtained
In case any user might find it useful. This works perfectly, IF THE CUSTOMER IS REGISTERED, then if the billing_company field is empty, it shows the name and surname, if the billing_company field has data, it shows billing_company