mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://stackoverflow.com/questions/66357034/change-payment-method-title-for-specific-products-in-woocommerce-checkout/66359464
17 lines
789 B
Text
17 lines
789 B
Text
add_filter( 'woocommerce_gateway_title', 'change_payment_gateway_title', 100, 2 );
|
|
function change_payment_gateway_title( $title, $payment_id ){
|
|
$targeted_payment_id = 'redsys_gw'; // Set your payment method ID
|
|
$targeted_product_ids = array(37, 53); // Set your product Ids
|
|
|
|
// Only on checkout page for specific payment method Id
|
|
if( is_checkout() && ! is_wc_endpoint_url() && $payment_id === $targeted_payment_id ) {
|
|
// Loop through cart items
|
|
foreach( WC()->cart->get_cart() as $item ) {
|
|
// Check for specific products: Change payment method title
|
|
if( in_array( $item['product_id'], $targeted_product_ids ) ) {
|
|
return __("Payment in installments", "woocommerce");
|
|
}
|
|
}
|
|
}
|
|
return $title;
|
|
}
|