• Resolved coatsy35

    (@coatsy35)


    Hi,

    How do you correctly set the below function to display the contents of the element? as it stands now it just prints the elements name instead of the content?

    function is_element_empty($element) {
    	if(empty($element)) {
    		return "{Billing First Name} {Billing Last Name}";
    	} else {
    		return "{Billing Company}";
    	}
    }

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter coatsy35

    (@coatsy35)

    I discovered I can use the following if there is only one item in my order, however if there are multiple items it replaces the result with the word “Array”. How do I fix this?

    // Add VAT onto individual item cost to generate individual item gross value including VAT
    function price_inc_vat($cost, $vat) {
    	$incvat=$cost+$vat;
    	return "$incvat";
    }

    I call it using: [price_inc_vat({Item Cost},{Item Tax})], do I need to put a foreach in there somewhere?

    • This reply was modified 4 years, 3 months ago by coatsy35.
    Plugin Author WP All Import

    (@wpallimport)

    Hi @coatsy35,

    I just posted an example snippet in your other thread that should be helpful: https://www.ads-software.com/support/topic/number-addition/#post-13728054. Basically if there are multiple items then the cost and tax elements will be an array, if there’s a single time then they’ll be strings.

    Thread Starter coatsy35

    (@coatsy35)

    Thanks, that response above of mine was meant to be in the other thread!

    For this thread, how do you get it to print the elements name instead of the tag? i.e. {Billing Company} in a function as per my question above?

    Plugin Author WP All Import

    (@wpallimport)

    Hey @coatsy35,

    My apologies for the confusion. You need to pass the elements to the function in order for it to be able to return them. For example:

    [is_element_empty({Billing Company},{Billing First Name},{Billing Last Name})]

    Then the code would look like this (note: untested example):

    function is_element_empty( $company, $first, $last ) {
    	if(empty($company)) {
    		return $first . ' ' . $last;
    	} else {
    		return $company;
    	}
    }
    • This reply was modified 4 years, 2 months ago by WP All Import.
    Plugin Author WP All Import

    (@wpallimport)

    Hi @coatsy35,

    I’m marking this as resolved since we haven’t heard back. Let us know if you still have questions about this.

    Anyone else, please open a new topic.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying Elements in Function’ is closed to new replies.