wc_update_240_shipping_methods آپدیت روش حمل و نقل ووکامرس نسخه 2.4.0

wc_update_240_shipping_methods آپدیت روش حمل و نقل ووکامرس نسخه 2.4.0

تابع ووکامرسی wc_update_240_shipping_methods – بروزرسانی روش های حمل و نقل ووکامرس به نسخه 2.4.0

Syntax – سینتکس

wc_update_240_shipping_methods(); 

Usage – نحوه استفاده

if ( !function_exists( 'wc_update_240_shipping_methods' ) ) { 
    require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-update-functions.php'; 
} 
 
  
// NOTICE! Understand what this does before running. 
$result = wc_update_240_shipping_methods(); 
    

Defined – محل تعریف

/includes/wc-update-functions.php

function wc_update_240_shipping_methods() { 
    global $wpdb; 
    /** 
     * Flat Rate Shipping. 
     * Update legacy options to new math based options. 
     */ 
    $shipping_methods = array( 
        'woocommerce_flat_rates' => new WC_Shipping_Legacy_Flat_Rate(),  
        'woocommerce_international_delivery_flat_rates' => new WC_Shipping_Legacy_International_Delivery(),  
 ); 
    foreach ( $shipping_methods as $flat_rate_option_key => $shipping_method ) { 
        // Stop this running more than once if routine is repeated 
        if ( version_compare( $shipping_method->get_option( 'version', 0 ), '2.4.0', '<' ) ) { 
            $has_classes = sizeof( WC()->shipping->get_shipping_classes() ) > 0; 
            $cost_key = $has_classes ? 'no_class_cost' : 'cost'; 
            $min_fee = $shipping_method->get_option( 'minimum_fee' ); 
            $math_cost_strings = array( 'cost' => array(), 'no_class_cost' => array() ); 
            $math_cost_strings[ $cost_key ][] = $shipping_method->get_option( 'cost' ); 
 
            if ( $fee = $shipping_method->get_option( 'fee' ) ) { 
                $math_cost_strings[ $cost_key ][] = strstr( $fee, '%' ) ? '[fee percent="' . str_replace( '%', '', $fee ) . '" min="' . esc_attr( $min_fee ) . '"]' : $fee; 
            } 
 
            foreach ( WC()->shipping->get_shipping_classes() as $shipping_class ) { 
                $rate_key = 'class_cost_' . $shipping_class->slug; 
                $math_cost_strings[ $rate_key ] = $math_cost_strings['no_class_cost']; 
            } 
 
            if ( $flat_rates = array_filter( (array) get_option( $flat_rate_option_key, array() ) ) ) { 
                foreach ( $flat_rates as $shipping_class => $rate ) { 
                    $rate_key = 'class_cost_' . $shipping_class; 
                    if ( $rate['cost'] || $rate['fee'] ) { 
                        $math_cost_strings[ $rate_key ][] = $rate['cost']; 
                        $math_cost_strings[ $rate_key ][] = strstr( $rate['fee'], '%' ) ? '[fee percent="' . str_replace( '%', '', $rate['fee'] ) . '" min="' . esc_attr( $min_fee ) . '"]' : $rate['fee']; 
                    } 
                } 
            } 
 
            if ( 'item' === $shipping_method->type ) { 
                foreach ( $math_cost_strings as $key => $math_cost_string ) { 
                    $math_cost_strings[ $key ] = array_filter( array_map( 'trim', $math_cost_strings[ $key ] ) ); 
                    if ( ! empty( $math_cost_strings[ $key ] ) ) { 
                        $last_key = max( 0, sizeof( $math_cost_strings[ $key ] ) - 1 ); 
                        $math_cost_strings[ $key ][0] = '( ' . $math_cost_strings[ $key ][0]; 
                        $math_cost_strings[ $key ][ $last_key ] .= ' ) * [qty]'; 
                    } 
                } 
            } 
 
            $math_cost_strings['cost'][] = $shipping_method->get_option( 'cost_per_order' ); 
 
            // Save settings 
            foreach ( $math_cost_strings as $option_id => $math_cost_string ) { 
                $shipping_method->settings[ $option_id ] = implode( ' + ', array_filter( $math_cost_string ) ); 
            } 
 
            $shipping_method->settings['version'] = '2.4.0'; 
            $shipping_method->settings['type'] = 'item' === $shipping_method->settings['type'] ? 'class' : $shipping_method->settings['type']; 
 
            update_option( $shipping_method->plugin_id . $shipping_method->id . '_settings', $shipping_method->settings ); 
        } 
    } 
} 

versions – نسخه ها

از نسخه : 3.0.2

نسخه فعلی : 3.0.6

دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2

ارسال نظر

جهت استفاده از کد حتما از تگ pre استفاده نمایید .

contact us