pronamic / wp-pronamic-pay

The Pronamic Pay plugin allows you to easily accept payments with payment methods like credit card, iDEAL, Bancontact and Sofort through a variety of payment providers on your WordPress website.
https://pronamicpay.com
34 stars 14 forks source link

Interference with Checkout Fields #304

Closed Mvgnu closed 2 years ago

Mvgnu commented 2 years ago

Woocommerce checkout fields being made optional is being overwritten by the pronamic pay Wordpress plugin, making it impossible to checkout when said fields are removed and impossible to make them optional when displayed but required set to false through filters in the fuctions.php.

Mvgnu commented 2 years ago

I was able to fix this by deactivating

add_filter( 'woocommerce_checkout_fields', array( __CLASS__, 'checkout_fields' ), 10, 1 );
add_action( 'woocommerce_checkout_update_order_meta', array( __CLASS__, 'checkout_update_order_meta' ), 10, 2 );

in pronamic-ideal/vendor/wp-pay-extensions/woocommerce/src/Extension.php

rvdsteege commented 2 years ago

Hello @Mvgnu, I wanted to see if we can improve on this so you don't have to make any changes in our plugin source files on future plugin updates. However, the below filter seems to work perfectly fine (also with different filter priorities) and I was unable to reproduce the issue. If you have any further details you can share to reproduce the issue, please let us know.

add_filter( 'woocommerce_checkout_fields', 'pronamic_woocommerce_checkout_fields', 10, 1 );

function pronamic_woocommerce_checkout_fields( $fields ) {
    // Check billing fields.
    if ( ! array_key_exists( 'billing', $fields ) ) {
        return $fields;
    }

    // Check billing last name field.
    if ( ! array_key_exists( 'billing_last_name', $fields['billing'] ) ) {
        return $fields;
    }

    // Make last name optional.
    if ( is_array( $fields['billing']['billing_last_name'] ) ) {
        $fields['billing']['billing_last_name']['required'] = false;
    }

    return $fields;
}