Plugin Directory

Changeset 2765806


Ignore:
Timestamp:
08/03/2022 01:26:29 PM (4 years ago)
Author:
lucascreativecode
Message:

Adicionado prazo de entrega

Location:
unienvios/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • unienvios/trunk/ClassUnienvios.php

    r2642517 r2765806  
    1414        $this->title              = $this->get_option('title'); // This can be added as an setting but for this example its forced.
    1515        $this->enabled              = $this->get_option('enabled');
     16        // $this->delivery_time              = $this->get_option('delivery_time');
     17        // $this->calculator              = $this->get_option('calculator');
    1618       
    1719
     
    3234    {
    3335        $this->form_fields = array(
     36            'title' => array(
     37                'title'         => __('Título'),
     38                'type'             => 'text',
     39                'description'     => __('Isso controla o título que o usuário vê durante o checkout.'),
     40                'default'        => __($this->method_title),
     41                'desc_tip'        => true
     42            ),
    3443            'enabled' => array(
    3544                'title'         => __('Ativar/Desativar'),
     
    3847                'default'         => 'yes',
    3948            ),
    40             'title' => array(
    41                 'title'         => __('Título'),
    42                 'type'             => 'text',
    43                 'description'     => __('Isso controla o título que o usuário vê durante o checkout.'),
    44                 'default'        => __($this->method_title),
    45                 'desc_tip'        => true
    46             )
     49            // 'delivery_time' => array(
     50            //     'title'         => __('Ativar/Desativar Prazo de Entrega'),
     51            //     'type'             => 'checkbox',
     52            //     'label'         => __('Mostrar prazo de entrega no carrinho'),
     53            //     'default'         => 'yes',
     54            // ),
     55            // 'calculator' => array(
     56            //     'title'         => __('Ativar/Desativar Calculadora de Frete'),
     57            //     'type'             => 'checkbox',
     58            //     'label'         => __('Ativar ou desativar campo de calcular frete na página do produto'),
     59            //     'default'         => 'yes',
     60            // ),
    4761        );
    4862    } // End init_form_fields()
     
    117131                ];
    118132
    119         //     wc_add_notice( __('debug: ', 'woothemes') .  json_encode($dimensoes), 'error' );
    120         // return;
    121 
    122         // wp_send_json($dimensoes);
    123 
    124         $api = new API_UNIENVIOS('https://api.unienvios.com.br');
    125         $dados = [];
    126         $dados['email'] = get_option('unienvios_options')['email'];
    127         $dados['senha'] = get_option('unienvios_options')['senha'];
    128         $dados['cep'] = str_replace("-", "", $package['destination']['postcode']);
    129         $dados['cart_subtotal'] = doubleval($package['cart_subtotal']);
    130 
    131 
    132 
    133         if ($dados['cep'] != "") {
    134             $quotation = $api->create_quotation($dados, $dimensoes);
    135             foreach ($quotation->quotations as $key => $qut) {
    136 
    137 
    138                 $name_minusculo = preg_replace("/[^\w\s]/", "", iconv("UTF-8", "ASCII//TRANSLIT", $qut->name));
    139                 $name_minusculo = strtolower(str_replace(" ", "_", $name_minusculo));
    140 
    141                 if ($name_minusculo == $this->id) {
    142                     $rate = array(
    143                         'label' => $this->title,
    144                         'cost' => $qut->final_price,
    145                         'calc_tax' => 'per_item'
    146                     );
    147 
     133               
     134                // wp_send_json($dimensoes);
     135               
     136                $api = new API_UNIENVIOS('https://api.unienvios.com.br');
     137                $dados = [];
     138                $dados['email'] = get_option('unienvios_options')['email'];
     139                $dados['senha'] = get_option('unienvios_options')['senha'];
     140                $dados['cep'] = str_replace("-", "", $package['destination']['postcode']);
     141                $dados['cart_subtotal'] = doubleval($package['cart_subtotal']);
     142               
     143               
     144               
     145                if ($dados['cep'] != "") {
     146                    $quotation = $api->create_quotation($dados, $dimensoes);
     147                    $array_delivery_time = [];
     148
     149                    foreach ($quotation->quotations as $key => $qut) {
     150                       
     151                        $name_minusculo = preg_replace("/[^\w\s]/", "", iconv("UTF-8", "ASCII//TRANSLIT", $qut->name));
     152                        $name_minusculo = strtolower(str_replace(" ", "_", $name_minusculo));
     153                       
     154                        array_push($array_delivery_time, ['qut_label' => $qut->name,'time'=>$qut->delivery_time]);
     155
     156                        if ($name_minusculo == $this->id) {
     157                            $rate = array(
     158                                'label' => $this->title,
     159                                'cost' => $qut->final_price,
     160                                'calc_tax' => 'per_item',
     161                                'delivery_time' => $qut->delivery_time
     162                            );
     163                        //     wc_add_notice( __('debug: ', 'woothemes') .  json_encode($rate), 'error' );
     164                        // return;
     165                           
    148166                    // Register the rate
    149167                    $this->add_rate($rate);
     
    173191                }
    174192            }
     193
     194            WC()->session->set(
     195                'array_delivery_time',
     196                $array_delivery_time
     197            );
    175198        }
    176199    }
  • unienvios/trunk/index.php

    r2752564 r2765806  
    44Plugin URI: https://unienvios.com.br/
    55Description: Plugin de Entrega
    6 Version: 1.2.2
     6Version: 1.3.0
    77Author: Unienvios
    88Author URI: https://unienvios.com.br/
     
    192192
    193193// add_action('woocommerce_init', 'teste2');
     194
     195function shipping_delivery_forecast( $shipping_method ) {
     196           
     197            $array_deliverys_times = WC()->session->get('array_delivery_time');
     198            // var_dump($shipping_method->label);
     199            foreach($array_deliverys_times as $times){
     200                if($times['qut_label'] == $shipping_method->label){
     201                    $total = $times['time'];
     202                }
     203            }
     204   
     205            if ( $total ) {
     206                /* translators: %d: days to delivery */
     207                echo '<p><small>' . esc_html( sprintf( _n( 'Entrega em %d dia útil', 'Entrega em %d dias úteis', $total, 'unienvios' ), $total ) ) . '</small></p>';
     208            }
     209}
     210
     211add_action( 'woocommerce_after_shipping_rate',  'shipping_delivery_forecast' , 100 );
  • unienvios/trunk/readme.txt

    r2752559 r2765806  
    55Requires at least: 4.7
    66Tested up to: 5.8
    7 Stable tag: 1.2.2
     7Stable tag: 1.3.0
    88Requires PHP: 7.2
    99License: GPLv3 or later
     
    7171
    7272* Adicionado calculo de medidas
     73
     74* Adicionado prazo de entrega no carrinho
     75= 1.3.0 =
Note: See TracChangeset for help on using the changeset viewer.