Thread Starter
Marisa
(@marisa2023)
$PG = new WC_Payment_Gateways();
$lg = $PG->get_available_payment_gateways();
The problem is the individual payment gatements are not returning ->title
Hi @marisa2023,
I understand how confusing it can be when your site behaves this way. Could you share a link to your site so I can take a closer look?
Thread Starter
Marisa
(@marisa2023)
I don’t want to publicly share details here.
Don’t you have a test website where you can test these things?
My second post here should help you.
$PG = new WC_Payment_Gateways();
$lg = $PG->get_available_payment_gateways();
The problem is the individual payment gatements are not returning ->title.
The fact that the PayPal payment methods return a title and the WooPayment ones do not, mean the bug is in your code. Also this is a new bug as the WooPayment code never behaved this way. For over a year, the WooPayment code return a title. Now in the last few weeks it is broken. This is an introduced bug in the WooPayments code.
Hi @marisa2023
We see that you’re hesitant to share details like the URL of your site, and we respect that. However, sometimes, how your site is setup with different plugins or theme can cause inconsistencies. For example, a theme might not be fully updated to match a new plugin version. Can you confirm if your theme, plugins (especially the ones related to the checkout page), and WordPress core have been updated recently?
Also to understand better, could you share a screenshot of how it looks on PayPal and Advanced Card Processing vs. on WooPayments? Please make sure to hide or blur any sensitive details (if any). Looking forward to your response.
Thread Starter
Marisa
(@marisa2023)
A screenshot is provided. To see it go to the link below.
https://ibb.co/P6jNHfw
I can confrim WordPress and all the plugins are up to date and the latest versions.
-
This reply was modified 5 months ago by
Marisa.
-
This reply was modified 5 months ago by
Marisa.
Hi @marisa2023,
Thank you for the screenshot. You can actually access the payment method name by using the method_title property for each gateway. Here’s an example of how you can retrieve the payment method name:
function list_payment_gateway_titles() {
$PG = new WC_Payment_Gateways();
$gateways = $PG->get_available_payment_gateways();
foreach ( $gateways as $gateway_id => $gateway ) {
// Use method_title as the title
$title = isset( $gateway->method_title ) ? $gateway->method_title : 'Title not set';
echo '<p><strong>Gateway ID:</strong> ' . esc_html( $gateway_id ) . '<br>';
echo '<strong>Title:</strong> ' . esc_html( $title ) . '</p>';
}
}
add_action( 'wp_footer', 'list_payment_gateway_titles' );
*I'm echoing the information inside the footer just for testing purposes.
This code will display the method_title of each available payment method, which corresponds to names like “Cash on delivery” or “WooPayments.”
However, please note that code customization is something out of our support scope. So, I would recommend you consult a developer if you need further customization.
I hope this helps, let us know if you have more questions.
Thread Starter
Marisa
(@marisa2023)
Thanks very much. I will try this soon.
Thread Starter
Marisa
(@marisa2023)
Your quick assistance has helped me resolve this matter. It is very much appreciated. Now I don’t have to worry about something like this not working.
I used ->get_title() rather than ->method_title . It seems for my case ->get_title() works, but not ->title
For me, it still doesn’t resolve anything. A lot of headache could’ve been avoided if they just included the title and description attributes like its defined in the Woo documentation.
Hey @hendrikhere ,
I’m sorry to hear that the previous custom code didn’t quite do the trick for you. Let’s try another approach! @marisa2023 mentioned that using ->get_title()
instead of ->method_title
helped in their case, so I’ve adjusted the code for you to test:
function list_payment_gateway_titles() {
// Get all installed payment gateways
$gateways = WC()->payment_gateways->payment_gateways();
foreach ( $gateways as $gateway_id => $gateway ) {
// Use get_title() method to retrieve the title
$title = $gateway->get_title();
echo '<p><strong>Gateway ID:</strong> ' . esc_html( $gateway_id ) . '<br>';
echo '<strong>Title:</strong> ' . esc_html( $title ) . '</p>';
}
}
add_action( 'wp_footer', 'list_payment_gateway_titles' );
Could you give this a try and see if it works better for you? Let me know how it goes!