Z
Z
zeaovede2022-04-11 05:08:16
PHP
zeaovede, 2022-04-11 05:08:16

How to display a description for two or more payment methods?

This is how the description is displayed for two payment methods. And it works

if ( ! defined( 'ABSPATH' ) ) {
  exit;
}
  $title = ($gateway->id=='enot') ? 'Описание-1.' : 'Описание-2';
?>
<li id="position-center" class="wc_payment_method payment_method_<?php echo esc_attr( $gateway->id ); ?>">
  <input id="payment_method_<?php echo esc_attr( $gateway->id ); ?>" type="radio" class="input-radio" name="payment_method" value="<?php echo esc_attr( $gateway->id ); ?>" <?php checked( $gateway->chosen, true ); ?> data-order_button_text="<?php echo esc_attr( $gateway->order_button_text ); ?>" />

  <label for="payment_method_<?php echo esc_attr( $gateway->id ); ?>" class="bs-tooltip primary mb-3" title="<?php echo $title; ?>" data-toggle="tooltip">
    <?php echo $gateway->get_icon(); /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */ ?>
  </label>
</li>


But when I tried to display the third payment method, nothing came of it. How to display a description for the third payment method?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Brumer, 2022-04-11
@zeaovede

$title = ($gateway->id=='enot') ? 'Описание-1.' : ( ($gateway->id=='Not enot') ? 'Описание-2' : 'Описание-3');
//
$title = ($gateway->id=='enot') ? 'Описание-1.' : ( ($gateway->id=='Not enot') ? 'Описание-2' : ( ($gateway->id=='Bla-Bla') ? 'Описание-3' : 'Описание-4' ) );

I
inFureal, 2022-04-11
@inFureal

switch (gateway->id) {
     case 'enot': $title = 'Описание-1'; break;
     case 'stripe': $title = 'Описание-2'; break;
     default: throw new \InvalidArgumentException("Неправильный способ оплаты");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question