Support » Plugin: Export any WordPress data to XML/CSV » Using the value from one column in another

  • Resolved dalea

    (@dalea)


    Is it possible to use the value returned in one field in another field?
    eg.
    Column one fetches name
    Column two needs to display the name from column one plus surrounding text

    I have tried global variables in a php function but no luck, see below:

    (column one function) function personalised_artwork_name ( $value ) {
    global $order_name;
    $order_name = $value;
    return $value;
    }
    Name returned for this function as required

    (column two function) function artwork_name ( $value ) {
    $order_name_artwork = &GLOBALS(‘order_name’);
    return $order_name_artwork;
    }

    Surrounding text part is not included here

    No value is displayed in column two

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor WP All Import

    (@wpallimport)

    Hi @dalea

    The best way to do this is to use a function on the “ID” element so that you can use functions like get_post_meta() and get_user_meta() to query the data. The ID element could be “Order ID”, “ID”, “Customer ID”, etc – it just depends on the data you’re querying. As an example, if you wanted to get the “Billing First Name” and “Billing Last Name” inside 1 column for a WooCommerce Orders export, here’s how you could do it:

    1) Click “Add Field” in your export, select “Customer User ID” in the top drop down, name your field, and enable the “Export the value returned by a PHP function” option.

    2) Use the following function on the field:

    function my_get_full_billing_name( $customer_id ) {
    	$first_name = get_user_meta( $customer_id, 'billing_first_name', true );
    	$last_name = get_user_meta( $customer_id, 'billing_last_name', true );
    	return $first_name . " " . $last_name;
    }

    This is what the set up should look like: https://d.pr/zcO3V9.

    Plugin Contributor WP All Import

    (@wpallimport)

    Marking this as resolved. @dalea if you have any further questions about this issue, feel free to respond here. Anyone else, please start a new thread.

    Thread Starter dalea

    (@dalea)

    Sorry for the delay in getting back to you in regards to this issue.

    I have tried out the method you provided, however it does not fully solve the issue I am having. For me the fields that I require are not within the same field type eg, Customer_id.

    Both of my fields are custom fields on each variation. My situation is that I need to get the value of an artwork field, which I can select under the “What field would you like to export?” but the second custom field (name) is also a separate field that I need to insert into the output value.

    In addition to this I need to also get the product name for the order for some if() loops

    An example of my custom function so far is:

    function get_personalised_file_name( $value ) {
    if(!empty($value)){
    $product_name = ( get product name for order )
    $person_name = ( get the value of the separate custom field )

    if(strpos($product_name, ‘XX’) !== false){
    $value_lower_case = strtolower( $person_name );
    $personalised_file_name = $value_lower_case . ‘-XXX.pdf’;
    return $personalised_file_name;
    } elseif (strpos($product_name, ‘XY’) !== false){
    $value_lower_case = strtolower( $person_name );
    $personalised_file_name = $value_lower_case . ‘-XYX.png’;
    return $personalised_file_name;
    } else { return $value; }
    }
    }

    Any help with this issue would be much appreciated.

    Thanks

    Plugin Contributor WP All Import

    (@wpallimport)

    Hey @dalea.

    We actually just pushed a new update that will make this a lot easier. Please update to the newest version and try using the new “Custom export field” feature: https://d.pr/z3pYfz.

    If that doesn’t help, we’ll need to take a look at the data on your site to advise further. In this case, please open a support ticket at http://www.wpallimport.com/support/ with more details so that we can help out.

    Thread Starter dalea

    (@dalea)

    Hi @wpallimport,

    Thank you for getting back to me in regards to this new feature. Is there any documentation available so that we can make full use of this new feature?

    Thanks again

    Plugin Contributor WP All Import

    (@wpallimport)

    Hi @dalea

    Unfortunately, there’s no documentation on it yet. To use it, you can just drag in the fields you need to export, and/or type static text, in the “Custom export field” text area. If you need to use PHP functions on the data, you can use the same syntax that is used in WP All Import: http://www.wpallimport.com/documentation/developers/execute-php/.

    If you run into any issues, please contact us at http://www.wpallimport.com/support/ and we’d be glad to answer any questions.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Using the value from one column in another’ is closed to new replies.