1

I've created an invoice theme for myself and I'm trying to get the invoice total in a custom column.

I've tried adapting the code I'm using within the template page to display this in the functions.php file but it's not working.

I'm getting an operand error where my multiplication operand is and I don't know why.

Here's my code (any help would be much appreciated).

if( $column_name == 'invoice_total' ) {
    $hours = 0; // This allows counting of each sub_field

    //* Set repeater variables

    $service_amount = get_post_meta( get_the_ID(), 'invoice_service_amount' );
    $service_quantity = get_post_meta( get_the_ID(), 'invoice_service_quantity' );

    $line_total = get_post_meta( get_the_ID(), 'invoice_service_quantity' ) *  get_post_meta( get_the_ID(), 'invoice_service_amount' );
    $hours += intval( get_post_meta( get_the_ID(), 'invoice_service_quantity' ) ); //intval: Get the integer value of a variable
    $late_fee =  get_post_meta( get_the_ID(), 'late_fee' );
    $hours_amount = get_post_meta( get_the_ID(), 'invoice_service_amount' );

    global $running_total;
    global $running_total_late;
        $running_total += get_post_meta( get_the_ID(), 'invoice_service_amount' ) * get_post_meta( get_the_ID(), 'invoice_service_quantity' );
        $running_total_late += $running_total + get_post_meta( get_the_ID(), 'late_fee' );

    echo '$'. $running_total;
}

There error I'm getting is in the $running_total line with the multiplication operand.

I should also point out I'm using ACF Pro to build my invoice form and the amounts and quantity are in a repeater field.

TIA!

closed as off-topic by Michael, Jacob Peattie, cjbj, bueltge, Jack Johansson Dec 19 '17 at 17:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2

On those lines get_post_meta() will return an array because by default the third argument of get_post_meta() is false.

If you want to return a single value you should call it like so:

get_post_meta( get_the_ID(), 'invoice_service_amount', true );

Additionally, you may want to get the post meta first and then ensure you have a value (wrapping that multiplication in a conditional statement to avoid errors). Perhaps something like:

$invoice_service_amount = get_post_meta( get_the_ID(), 'invoice_service_amount', true );
$invoice_service_quantity = get_post_meta( get_the_ID(), 'invoice_service_quantity', true );
if ( ! empty( $invoice_service_amount ) && ! empty( $invoice_service_quantity ) ) {
    $line_total = absint( $invoice_service_amount ) * absint( $invoice_service_quantity );
else {
    $line_total = 0;
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.