0

after installing payment gateway in WooCommerce, first there was the following error "Cannot modify header information - headers already sent by tap-gateway.php:69".

After searching in this file, I edited it and remove from this:

        $this->ui_mode = $this->get_option('ui_mode');
        $this->save_card = $this->get_option('save_card');
        ?>

        <?php
        add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ), 11);
        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );

the following:

        ?>

        <?php

I hope what i did was right.

Any way now I am having another issue with the same file that I couldn't fix: "A non-numeric value encountered in public_html/wp-content/plugins/tap-payments/tap-gateway.php on line 262"

Here is the related code:

 // line 261
 $sub_total += ($item['quantity'] * $product['price']);

 // line 262
 echo '<input type="hidden" name="items_bulk[]" data-name="'.$item['data']->name.'" data-quantity="'.$item['quantity'].'"

can some one help?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399

1 Answers1

0

I'm going to guess that you meant line 261, as

$sub_total += ($item['quantity'] * $product['price']);

could certainly cause that warning if $item['quantity'] or $product['price'] contained anything other than a numeric value.

Rewriting line 261 to

$sub_total += (intval($item['quantity']) * floatval($product['price']));

would ensure they are cast to integers prior to multiplying them.

UPDATE

Change line

echo '<input type="hidden" name="items_bulk[]" data-name="'.$item['data']->name.'" data-quantity="'.$item['quantity'].'" data-sale-price="'.$item['data']->sale_price.'" data-item-product-id="'.$item['product_id'].'" data-product-total-amount="'.$item['quantity']*$item['data']->sale_price.'" class="items_bulk">';

to

echo '<input type="hidden" name="items_bulk[]" data-name="' . $item['data']->name . '" data-quantity="' . $item['quantity'] . '" data-sale-price="' . $item['data']->sale_price . '" data-item-product-id="' . $item['product_id'] . '" data-product-total-amount="' . intval($item['quantity']) * floatval($item['data']->sale_price) . '" class="items_bulk">';

for the same reason as above.

I do however echo LoicTheAztec's comment on your question that this payment gateway seems badly written.

Sammy
  • 335
  • 2
  • 12
  • nope that didnt work still gives me errorPHP Warning: A non-numeric value encountered in public_html/wp-content/plugins/tap-payments/tap-gateway.php on line 262 – Ahmad Taher Mar 07 '21 at 02:21
  • nope that didnt work still gives me errorPHP Warning: A non-numeric value encountered in public_html/wp-content/plugins/tap-payments/tap-gateway.php on line 262 – Ahmad Taher Mar 07 '21 at 02:25
  • Note that the product price is a float number, not an integer… Also in that case, it's recommended to use `intval()` and/or `floatval()`than `(int)` and/or `(float)`. – LoicTheAztec Mar 07 '21 at 02:31
  • @LoicTheAztec quite right, thank you for pointing that out :-) I've updated my answer for clarity – Sammy Mar 07 '21 at 02:41
  • @LoicTheAztec am not that good in PHP just starting up, if you dont mind could you please solve it for me – Ahmad Taher Mar 07 '21 at 02:42
  • @Sam sorry Sam .. still it gives me the same error – Ahmad Taher Mar 07 '21 at 02:45
  • @AhmadTaher could you link to where you got the plugin from, as https://wordpress.org/plugins/tap-payments/ doesn't seem to have `tap-gateway.php` (and hasn't been updated for a year..) – Sammy Mar 07 '21 at 02:48
  • @Sam they provide V2.0 from their side .. you can download it from here https://filebin.net/lhsxjtpnzo6tgoag/tap-payments__40_.zip?t=byfj3542 – Ahmad Taher Mar 07 '21 at 02:54
  • @AhmadTaher I've updated my answer above – Sammy Mar 07 '21 at 03:27
  • @Sam that work like a charm ... thanks man ..u made my day :) – Ahmad Taher Mar 07 '21 at 03:39
  • Note that since WooCommerce 3, `floatval($item['data']->sale_price)` should be replaced by `floatval($item['data']->get_sale_price())` as product (object) properties are protected and doesn't have to be accessed directly. – LoicTheAztec Mar 07 '21 at 10:19