تابع wc_update_200_taxrates بروزرسانی نرخ مالیات ووکامرس به نسخه 2

تابع wc_update_200_taxrates بروزرسانی نرخ مالیات ووکامرس به نسخه 2

تابع ووکامرسی wc_update_200_taxrates – بروزرسانی نرخ مالیات ووکامرس به نسخه 2

Syntax – سینتکس

wc_update_200_taxrates(); 

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

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

Defined – محل تعریف

/includes/wc-update-functions.php

function wc_update_200_taxrates() { 
    global $wpdb; 
 
    // Update tax rates 
    $loop = 0; 
    $tax_rates = get_option( 'woocommerce_tax_rates' ); 
 
    if ( $tax_rates ) 
        foreach ( $tax_rates as $tax_rate ) { 
 
            foreach ( $tax_rate['countries'] as $country => $states ) { 
 
                $states = array_reverse( $states ); 
 
                foreach ( $states as $state ) { 
 
                    if ( '*' == $state ) { 
                        $state = ''; 
                    } 
 
                    $wpdb->insert( 
                        $wpdb->prefix . "woocommerce_tax_rates",  
                        array( 
                            'tax_rate_country' => $country,  
                            'tax_rate_state' => $state,  
                            'tax_rate' => $tax_rate['rate'],  
                            'tax_rate_name' => $tax_rate['label'],  
                            'tax_rate_priority' => 1,  
                            'tax_rate_compound' => ( 'yes' === $tax_rate['compound'] ) ? 1 : 0,  
                            'tax_rate_shipping' => ( 'yes' === $tax_rate['shipping'] ) ? 1 : 0,  
                            'tax_rate_order' => $loop,  
                            'tax_rate_class' => $tax_rate['class'],  
 ) 
 ); 
 
                    $loop++; 
                } 
            } 
        } 
 
    $local_tax_rates = get_option( 'woocommerce_local_tax_rates' ); 
 
    if ( $local_tax_rates ) 
        foreach ( $local_tax_rates as $tax_rate ) { 
 
            $location_type = ( 'postcode' === $tax_rate['location_type'] ) ? 'postcode' : 'city'; 
 
            if ( '*' == $tax_rate['state'] ) { 
                $tax_rate['state'] = ''; 
            } 
 
            $wpdb->insert( 
                $wpdb->prefix . "woocommerce_tax_rates",  
                array( 
                    'tax_rate_country' => $tax_rate['country'],  
                    'tax_rate_state' => $tax_rate['state'],  
                    'tax_rate' => $tax_rate['rate'],  
                    'tax_rate_name' => $tax_rate['label'],  
                    'tax_rate_priority' => 2,  
                    'tax_rate_compound' => ( 'yes' === $tax_rate['compound'] ) ? 1 : 0,  
                    'tax_rate_shipping' => ( 'yes' === $tax_rate['shipping'] ) ? 1 : 0,  
                    'tax_rate_order' => $loop,  
                    'tax_rate_class' => $tax_rate['class'],  
 ) 
 ); 
 
            $tax_rate_id = $wpdb->insert_id; 
 
            if ( $tax_rate['locations'] ) { 
                foreach ( $tax_rate['locations'] as $location ) { 
 
                    $wpdb->insert( 
                        $wpdb->prefix . "woocommerce_tax_rate_locations",  
                        array( 
                            'location_code' => $location,  
                            'tax_rate_id' => $tax_rate_id,  
                            'location_type' => $location_type,  
 ) 
 ); 
 
                } 
            } 
 
            $loop++; 
        } 
 
    update_option( 'woocommerce_tax_rates_backup', $tax_rates ); 
    update_option( 'woocommerce_local_tax_rates_backup', $local_tax_rates ); 
    delete_option( 'woocommerce_tax_rates' ); 
    delete_option( 'woocommerce_local_tax_rates' ); 
} 

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