php - WordPress WooCommerce custom payment gateway development issue
Get the solution ↓↓↓I want to set title for my payment gateway, but on the checkout form the title doesn't appear. Is there any way to set an option to imitate settings saving, but only for one option (title)? Because if I set inpayment_fields
function (on checkout load), it doesn't work.
function *****_init_payment_class() {
...
class ****Payment extends WC_Payment_Gateway {
...
public function payment_fields() {
$res = $this->sendRequest('GET', "payment-service/view/$this->payment_service_id");
if($res['_statusCode'] == 200) {
$paymentService = $res['data'];
$this->title = $paymentService['name'];
...\wp-content\plugins\woocommerce\templates\checkout\payment-method.php
<li 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 ); ?>">
<?php echo $gateway->get_title(); /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */ ?> <?php echo $gateway->get_icon(); /* phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped */ ?>
</label>
<?php if ( $gateway->has_fields() || $gateway->get_description() ) : ?>
<div class="payment_box payment_method_<?php echo esc_attr( $gateway->id ); ?>" <?php if ( ! $gateway->chosen ) : /* phpcs:ignore Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace */ ?>style="display:none;"<?php endif; /* phpcs:ignore Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace */ ?>>
<?php $gateway->payment_fields(); ?>
</div>
<?php endif; ?>
So here basically I see <?php echo $gateway->get_title(); code, where I expect my title to be. But it's actually empty. I want to set title in payment_fields() hook/function. Is there a way to do it?
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string deprecated
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.