Woocommerce找不到关于获取送货方式的错误

时间:2019-09-26 10:22:35

标签: methods woocommerce shipping

我测试添加一个插件交付的功能,但是我的新配置没有保持活动状态。您可以在这段代码中查找并帮助我吗?

当我激活此代码并在结帐时更改邮政编码时,延迟更改1秒钟,然后再进行更改。

add_filter( 'iconic_wds_min_delivery_date','iconic_change_min_delivery_date4', 10, 2 );
function iconic_change_min_delivery_date4( $min123 ) {
    $chosen_shipping = $order ? iconic_get_shipping_methods( $order ) : iconic_get_selected_shipping_method();

    if ( ! $chosen_shipping ) {
        return $min123;
    }

    if ( $chosen_shipping === 'flat_rate:11' ) {
    $days_to_add = 4;
        return array(
        'days_to_add' => $days_to_add,
        'timestamp'   => strtotime( "+" . $days_to_add . " day", current_time( 'timestamp' ) ),
    );
    }
    if ( $chosen_shipping === 'flat_rate:1' ) {
    $hours_to_add = 360;

    // This filter returns an array containing the days to add and a timestamp.
    return array(
        'hours_to_add' => $hours_to_add,
        'timestamp'   => strtotime( "+" . $hours_to_add . " hour", current_time( 'timestamp' ) ),
    );
    }

}

/**
 * Get order shipping method.
 *
 * @param WC_Order $order
 *
 * @return bool|string
 */
function iconic_get_order_shipping_method( $order ) {
    $chosen_methods = $order->get_shipping_methods();

    if ( empty( $chosen_methods ) ) {
        return false;
    }

    $chosen_shipping = array_shift( $chosen_methods );
    return sprintf( '%s:%s', $chosen_shipping->get_method_id(), $chosen_shipping->get_instance_id() );
}

/**
 * Get selected shipping method.
 *
 * @return string|bool
 */
function iconic_get_selected_shipping_method() {
    if ( is_admin() ) {
        return false;
    }

    $chosen_methods  = WC()->session->get( 'chosen_shipping_methods' );

    if ( empty( $chosen_methods ) ) {
        return false;
    }

    return $chosen_methods[0];
}

0 个答案:

没有答案