Woocommerce:禁用约会取消的登录要求 URL 地址 [wp nonce]

Woocommerce: Disable login requirement for appointment cancelation URL adress [wp nonce]

我正在使用 woocommerce + 约会日历插件。人们可以直接从产品预约并创建购买。

如果他们想取消这个约会,他们可以在我的帐户区域点击取消按钮来取消。

取消 URL 地址段由系统生成,如下所示:

/?cancel_appointment=true&appointment_id=442&redirect&_wpnonce=c328e0bab6

当您注销时,它不起作用,当您登录时,您的约会状态将更改为已取消。

我需要做的是更改 URL 授权的要求,这样当您注销时,它会让您取消约会,因为这里创建帐户对客户来说真的很烦人。

这是我在插件文件中找到的部分代码。也许它应该有所帮助。

/**
 * Returns the cancel URL for an appointment
 *
 * @param string $redirect
 *
 * @return string
 */
public function get_cancel_url( $redirect = '' ) {
    $cancel_page = get_permalink( wc_get_page_id( '' ) );

    if ( ! $cancel_page ) {
        $cancel_page = home_url();
    }

    return apply_filters(
        'appointments_cancel_appointment_url',
        wp_nonce_url(
            add_query_arg(
                array(
                    'cancel_appointment' => 'true',
                    'appointment_id'     => $this->get_id(),
                    'redirect'           => $redirect,
                ),
                $cancel_page
            ),
            'woocommerce-appointments-cancel_appointment'
        ),
        $this
    );
}

我找到的另一个代码在这里

<?php
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

/**
* Handle frontend forms
*/
class WC_Appointment_Form_Handler {

/**
 * Hook in methods
 */
public static function init() {
    add_action( 'init', array( __CLASS__, 'cancel_appointment' ), 20 );
}

/**
 * Cancel an appointment.
 */
public static function cancel_appointment() {
    if ( isset( $_GET['cancel_appointment'] ) && isset( 
 $_GET['appointment_id'] ) ) {

        $appointment_id         = absint( $_GET['appointment_id'] );
        $appointment            = get_wc_appointment( $appointment_id );
        $appointment_can_cancel = $appointment->has_status( get_wc_appointment_statuses( 'cancel' ) );
        $redirect               = $_GET['redirect'];
        $is_wc_appointment      = is_a( $appointment, 'WC_Appointment' ) ? true : false;

        if ( $appointment->has_status( 'cancelled' ) ) {
            // Message: Already cancelled - take no action.
            wc_add_notice( __( 'Your appointment has already been cancelled.', 'woocommerce-appointments' ), 'notice' );

        } elseif ( $is_wc_appointment && $appointment_can_cancel && $appointment->get_id() == $appointment_id && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'woocommerce-appointments-cancel_appointment' ) ) {
            // Cancel the appointment
            $appointment->update_status( 'cancelled' );
            WC_Cache_Helper::get_transient_version( 'appointments', true );

            // Message.
            wc_add_notice( apply_filters( 'woocommerce_appointment_cancelled_notice', __( 'Your appointment has been cancelled.', 'woocommerce-appointments' ) ), apply_filters( 'woocommerce_appointment_cancelled_notice_type', 'notice' ) );

            do_action( 'woocommerce_appointments_cancelled_appointment', $appointment->get_id() );
        } elseif ( ! $appointment_can_cancel ) {
            wc_add_notice( __( 'Your appointment can no longer be cancelled. Please contact us if you need assistance.', 'woocommerce-appointments' ), 'error' );
        } else {
            wc_add_notice( __( 'Invalid appointment.', 'woocommerce-appointments' ), 'error' );
        }

        if ( $redirect ) {
            wp_safe_redirect( $redirect );
            exit;
        }
    }
}
}

WC_Appointment_Form_Handler::init();

如果您需要代码中的任何其他内容,我可以搜索它。因为这是我第一次遇到这样的问题。

谢谢大家的帮助。

已通过

的代码编辑修复
elseif ( $is_wc_appointment && $appointment_can_cancel && $appointment->get_id() == $appointment_id && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'woocommerce-appointments-cancel_appointment' ) ) {

elseif ( $is_wc_appointment && $appointment_can_cancel && $appointment->get_id() == $appointment_id) {