php 兼容多厂商市场的WooCommerce会员资格

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 兼容多厂商市场的WooCommerce会员资格相关的知识,希望对你有一定的参考价值。

add_action( 'after_wcfm_products_manage_meta_save', 'wceb_compatibility_with_wcfm', 10, 2 );

function wceb_compatibility_with_wcfm( $id, $data ) {

    $booking_data = array(
        'bookable'                => isset( $data['_booking_option'] ) ? 'yes' : false,
        'dates'                   => isset( $data['_booking_dates'] ) ? $data['_booking_dates'] : '',
        'booking_min'             => isset( $data['_booking_min'] ) ? $data['_booking_min'] : '',
        'booking_max'             => isset( $data['_booking_max'] ) ? $data['_booking_max'] : '',
        'first_available_date'    => isset( $data['_first_available_date'] ) ? $data['_first_available_date'] : '',
        'booking_duration'        => isset( $data['_booking_duration'] ) ? $data['_booking_duration'] : '',
        'custom_booking_duration' => isset( $data['_custom_booking_duration'] ) ? $data['_custom_booking_duration'] : ''
    );

    $all_bookable = get_option( 'wceb_all_bookable' );
    $is_bookable  = isset( $booking_data['bookable'] ) ? esc_html( $booking_data['bookable'] ) : false;

    if ( ! empty( $all_bookable ) && $all_bookable === 'yes' ) {
        $is_bookable = 'yes';
    }

    $data = array(
        'booking_min'          => $booking_data['booking_min'],
        'booking_max'          => $booking_data['booking_max'],
        'first_available_date' => $booking_data['first_available_date']
    );

    foreach ( $data as $name => $value ) {
        
        switch ( $value ) {
            case '' :
                ${$name} = '';
            break;

            case 0 :
                ${$name} = '0';
            break;

            default :
                ${$name} = absint( $value );
            break;
        }
    }

    if ( $booking_min != 0 && $booking_max != 0 && $booking_min > $booking_max ) {
        WC_Admin_Meta_Boxes::add_error( __( 'Minimum booking duration must be inferior to maximum booking duration', 'woocommerce-easy-booking-system' ) );
    } else {
        update_post_meta( $id, '_booking_min', $booking_min );
        update_post_meta( $id, '_booking_max', $booking_max );
    }

    $booking_duration = sanitize_text_field( $booking_data['booking_duration'] );

    $duration = 1;
    switch ( $booking_duration ) {
        case 'global' :
            $duration = '';
        break;
        case 'parent' :
            $duration = '';
        break;
        case 'days' :
            $duration = 1;
        break;
        case 'weeks' :
            $duration = 7;
        break;
        case 'custom' :

            if ( ! empty( $booking_data['custom_booking_duration'] ) ) {

                $duration = absint( $booking_data['custom_booking_duration'] );

                if ( $duration <= 0 ) {
                    $duration = 1;
                }

            } else {
                $duration = '';
            }

        break;
        default :
            $duration = 1;
        break;
    }

    $dates = 'two';

    if ( ! empty( $booking_data['dates'] )
        && ( $booking_data['dates'] === 'one'
        || $booking_data['dates'] === 'two'
        || $booking_data['dates'] === 'parent'
        || $booking_data['dates'] === 'global' ) ) {

        $dates = sanitize_text_field( $booking_data['dates'] );

    }
    
    update_post_meta( $id, '_booking_dates', $dates );
    update_post_meta( $id, '_booking_duration', $booking_duration );
    update_post_meta( $id, '_custom_booking_duration', $duration );
    update_post_meta( $id, '_first_available_date', $first_available_date );
    update_post_meta( $id, '_booking_option', $is_bookable );

}

以上是关于php 兼容多厂商市场的WooCommerce会员资格的主要内容,如果未能解决你的问题,请参考以下文章

php 查询WooCommerce会员资格和FacetWP

php 查询WooCommerce会员资格和FacetWP

php 查询WooCommerce会员资格和FacetWP

php WooCommerce会员 - 检查用户是否是计划的成员

php WooCommerce会员 - 检查用户是否是计划的成员

php WooCommerce社交登录插件前端类兼容NextMove感谢WooCommerce页面