Plugin Directory

Changeset 3435502


Ignore:
Timestamp:
01/08/2026 09:57:20 PM (3 months ago)
Author:
peachpay
Message:

1.120.2

Location:
peachpay-for-woocommerce
Files:
924 added
5 edited

Legend:

Unmodified
Added
Removed
  • peachpay-for-woocommerce/trunk/changelog.txt

    r3433889 r3435502  
    11*** PeachPay for WooCommerce Changelog ***
     2
     32026-01-08 - version 1.120.2
     4* Fix(convesiopay): Ensures payment methods respect the WooCommerce orientation
    25
    362026-01-06 - version 1.120.1
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/admin/class-peachpay-admin-convesiopay-integration.php

    r3385397 r3435502  
    767767        }
    768768
    769         // Always show all 3 main payment methods regardless of API response
     769        // Define the EXPLICIT order we want payment methods to appear
     770        // This ensures consistent ordering across all environments (Card first, then Apple Pay, then Crypto)
    770771        $target_payment_methods = array( 'Card', 'Apple Pay', 'Crypto' );
    771772        $filtered_gateways = array();
    772773
    773         foreach ( $all_gateways as $gateway ) {
    774             $gateway_title = $gateway->title;
    775 
    776             // Include gateway if it matches one of our target payment methods
    777             if ( in_array( $gateway_title, $target_payment_methods, true ) ) {
    778                 $filtered_gateways[] = $gateway;
     774        // Iterate through target methods IN ORDER (not through all_gateways)
     775        // This guarantees the display order matches our defined order
     776        foreach ( $target_payment_methods as $target_title ) {
     777            foreach ( $all_gateways as $gateway ) {
     778                if ( $gateway->title === $target_title ) {
     779                    $filtered_gateways[] = $gateway;
     780                    break; // Found this method, move to next target
     781                }
    779782            }
    780783        }
  • peachpay-for-woocommerce/trunk/core/payments/convesiopay/hooks.php

    r3433272 r3435502  
    2222add_action( 'woocommerce_store_api_cart_select_payment_method', 'peachpay_convesiopay_force_fee_recalculation' );
    2323add_action( 'rest_api_init', 'peachpay_convesiopay_register_store_api_hooks' );
     24
     25// Sync unified gateway position with Card gateway position on checkout
     26// The unified gateway is hidden from admin, so we position it where the Card gateway is set
     27// This ensures the checkout order matches what users set in WooCommerce > Settings > Payments
     28add_filter( 'woocommerce_available_payment_gateways', 'peachpay_convesiopay_position_unified_gateway', 100 );
     29
     30/**
     31 * Position the unified gateway where the Card gateway would be.
     32 * Since the unified gateway is hidden from WooCommerce Payments admin,
     33 * we use the Card gateway's position to determine where unified should appear on checkout.
     34 *
     35 * @param array $available_gateways Available payment gateways.
     36 * @return array Reordered gateways.
     37 */
     38function peachpay_convesiopay_position_unified_gateway( $available_gateways ) {
     39    if ( empty( $available_gateways ) || ! is_array( $available_gateways ) ) {
     40        return $available_gateways;
     41    }
     42
     43    // Check if unified gateway is present
     44    if ( ! isset( $available_gateways['peachpay_convesiopay_unified'] ) ) {
     45        return $available_gateways;
     46    }
     47
     48    // Get the saved gateway order
     49    $gateway_order = get_option( 'woocommerce_gateway_order', array() );
     50
     51    // Find the Card gateway's position (this is what users can drag in admin)
     52    if ( ! isset( $gateway_order['peachpay_convesiopay_card'] ) ) {
     53        // If Card gateway has no saved position, leave unified where WooCommerce put it
     54        return $available_gateways;
     55    }
     56
     57    $card_position = (int) $gateway_order['peachpay_convesiopay_card'];
     58
     59    // Remove unified gateway from its current position
     60    $unified_gateway = $available_gateways['peachpay_convesiopay_unified'];
     61    unset( $available_gateways['peachpay_convesiopay_unified'] );
     62
     63    // Rebuild the array with unified at the Card gateway's position
     64    $result = array();
     65    $position = 0;
     66    $unified_inserted = false;
     67
     68    foreach ( $available_gateways as $gateway_id => $gateway ) {
     69        // Get this gateway's saved position
     70        $this_position = isset( $gateway_order[ $gateway_id ] ) ? (int) $gateway_order[ $gateway_id ] : 999;
     71
     72        // Insert unified gateway when we reach or pass the card's position
     73        if ( ! $unified_inserted && $this_position >= $card_position ) {
     74            $result['peachpay_convesiopay_unified'] = $unified_gateway;
     75            $unified_inserted = true;
     76        }
     77
     78        $result[ $gateway_id ] = $gateway;
     79        $position++;
     80    }
     81
     82    // If unified wasn't inserted yet (card position is at the end), add it now
     83    if ( ! $unified_inserted ) {
     84        $result['peachpay_convesiopay_unified'] = $unified_gateway;
     85    }
     86
     87    return $result;
     88}
    2489
    2590/**
     
    52117}
    53118
    54 // Prioritize ConvesioPay Card gateway in WooCommerce payment settings
    55 add_filter( 'woocommerce_payment_gateways', function( $gateways ) {
    56     $priority_gateways = [
    57         'PeachPay_ConvesioPay_Card_Gateway',
    58         'PeachPay_ConvesioPay_ApplePay_Gateway',
    59         'PeachPay_ConvesioPay_BTCPay_Gateway',
    60     ];
    61 
    62     $priorities = [];
    63 
    64     // Extract priority gateways in the order defined above
    65     foreach ( $priority_gateways as $priority_gateway ) {
    66                 $key = array_search($priority_gateway, $gateways);
    67                 if ($key !== false) {
    68                     unset($gateways[$key]);
    69                     $priorities[] = $priority_gateway;
    70                 }
    71         }
    72         //exclude PeachPay_ConvesioPay_Unified_Gateway
    73         // $exkey = array_search('PeachPay_ConvesioPay_Unified_Gateway', $gateways);
    74         //     if ($key !== false) {
    75         //         unset($gateways[$exkey]);
    76         //     }
    77     // Reindex remaining gateways
    78     $gateways = array_merge( $priorities, $gateways );
    79     return $gateways;
    80 }, 20 );
    81 
    82 
    83 
     119
     120// Set ConvesioPay as the default selected payment method on checkout
     121// This ensures Credit Card is checked/selected by default when available
     122add_action( 'template_redirect', function() {
     123    // Only run on checkout page (not on order endpoints like order-received)
     124    if ( ! is_checkout() || is_wc_endpoint_url() ) {
     125        return;
     126    }
     127
     128    // Check if WooCommerce session is available
     129    if ( ! WC()->session ) {
     130        return;
     131    }
     132
     133    // Define ConvesioPay gateway IDs in priority order
     134    $convesiopay_gateway_ids = array(
     135        'peachpay_convesiopay_unified',
     136        'peachpay_convesiopay_card',
     137    );
     138
     139    // Get available payment gateways
     140    $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
     141   
     142    if ( empty( $available_gateways ) ) {
     143        return;
     144    }
     145
     146    // Find the first available ConvesioPay gateway
     147    $default_gateway_id = null;
     148    foreach ( $convesiopay_gateway_ids as $gateway_id ) {
     149        if ( isset( $available_gateways[ $gateway_id ] ) ) {
     150            $default_gateway_id = $gateway_id;
     151            break;
     152        }
     153    }
     154
     155    // If no ConvesioPay gateway is available, don't change the default
     156    if ( ! $default_gateway_id ) {
     157        return;
     158    }
     159
     160    // Get the currently chosen payment method
     161    $chosen_payment_method = WC()->session->get( 'chosen_payment_method' );
     162
     163    // Only set default if:
     164    // 1. No payment method has been chosen yet, OR
     165    // 2. The previously chosen method is not available
     166    if ( empty( $chosen_payment_method ) || ! isset( $available_gateways[ $chosen_payment_method ] ) ) {
     167        WC()->session->set( 'chosen_payment_method', $default_gateway_id );
     168    }
     169}, 10 );
    84170
    85171
  • peachpay-for-woocommerce/trunk/peachpay.php

    r3433889 r3435502  
    44 * Plugin URI: https://woocommerce.com/products/peachpay
    55 * Description: Connect and manage all your payment methods, offer shoppers a beautiful Express Checkout, and reduce cart abandonment.
    6  * Version: 1.120.1
     6 * Version: 1.120.2
    77 * Text Domain: peachpay-for-woocommerce
    88 * Domain Path: /languages
  • peachpay-for-woocommerce/trunk/readme.txt

    r3433889 r3435502  
    44Requires at least: 5.8
    55Tested up to: 6.8.1
    6 Stable tag: 1.120.1
     6Stable tag: 1.120.2
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    262262
    263263== Changelog ==
     264
     265= 1.120.2 =
     266* Fix(convesiopay): Ensures payment methods respect the WooCommerce orientation
    264267
    265268= 1.120.1 =
Note: See TracChangeset for help on using the changeset viewer.