Woocommerce:禁用约会取消URL地址的登录要求[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.','error' );
        } else {
            wc_add_notice( __( 'Invalid appointment.','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) {

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...