首页 > 解决方案 > 可持续地覆盖/禁用 WooCommerce/Wordpress 核心功能 (PayPal IPN)

问题描述

基本上我们有一个相当复杂的工作流程,为了节省时间,我宁愿不做太多细节。我得出的结论是,我们需要禁用 PayPal IPN 处理程序中的金额验证,因为它会破坏我们使用的订单状态的自定义工作流程。

https://github.com/woocommerce/woocommerce/blob/b19500728b4b292562afb65eb3a0c0f50d5859de/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php

有问题的代码

$this->validate_amount( $order, $posted['mc_gross'] );

在第 195 行,解决它的“直截了​​当”/“head trough the wall”的方法是我显然可以进入插件编辑器并注释掉那段代码,这将解决我们遇到的问题,但显然这不是一个非常有用的解决方案,因为每次 WooCommerce 更新时它都会被覆盖

这是调用的函数:

    /**
     * Check payment amount from IPN matches the order.
     *
     * @param WC_Order $order  Order object.
     * @param int      $amount Amount to validate.
     */
    protected function validate_amount( $order, $amount ) {
        if ( number_format( $order->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
            WC_Gateway_Paypal::log( 'Payment error: Amounts do not match (gross ' . $amount . ')' );

            /* translators: %s: Amount. */
            $order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'woocommerce' ), $amount ) );
            exit;
        }
    }

从第 148 行开始。基本上我想禁用订单状态更新。我对 PHP 或 Wordpress 的了解都不够,甚至不知道在谷歌搜索时要寻找什么,因为我完全来自不同的语言,只是偶然发现了这一点。我可以覆盖/覆盖该函数以更改其在例如functions.php中的行为,或者什么是“正确”的方法来解决这个问题,而不必继承和自定义整个网关作为一个全新的东西?

标签: phpwordpresswoocommercepaypal

解决方案


推荐阅读