Plugin Directory

Changeset 3101414


Ignore:
Timestamp:
06/11/2024 08:37:44 PM (21 months ago)
Author:
shipbubble
Message:

Free shipping at checkout fix and currency converter optimizer

Location:
shipbubble
Files:
45 added
9 edited

Legend:

Unmodified
Added
Removed
  • shipbubble/trunk/admin/woocommerce/async-create-shipment.php

    r3010288 r3101414  
    11<?php
    22
    3 // enqueue scripts
    4 function ajax_enqueue_scripts_create_shipment($hook)
    5 {
    6     // check if our page
    7     if ('post.php' !== $hook) return;
     3    // enqueue scripts
     4    function ajax_enqueue_scripts_create_shipment( $hook )
     5    {
     6        // check if our page
     7        if ( 'post.php' !== $hook ) return;
     8       
     9        // define script url
     10        $script_url = plugins_url( '/js/ajax-create-shipment.js', plugin_dir_path( __FILE__ ) );
    811
    9     // define script url
    10     $script_url = plugins_url('/js/ajax-create-shipment.js', plugin_dir_path(__FILE__));
     12        // enqueue script
     13        wp_enqueue_script( 'ajax-wc-admin', $script_url, array( 'jquery' ) );
    1114
    12     // enqueue script
    13     wp_enqueue_script('ajax-wc-admin', $script_url, array('jquery'));
     15        // create nonce
     16        $nonce = wp_create_nonce( 'ajax_wc_admin' );
    1417
    15     // create nonce
    16     $nonce = wp_create_nonce('ajax_wc_admin');
     18        // define script
     19        $script = array( 'nonce' => $nonce );
    1720
    18     // define script
    19     $script = array('nonce' => $nonce);
     21        // localize script
     22        wp_localize_script( 'ajax-wc-admin', 'ajax_wc_admin', $script );
    2023
    21     // localize script
    22     wp_localize_script('ajax-wc-admin', 'ajax_wc_admin', $script);
    23 }
     24    }
     25   
     26
     27    add_action( 'admin_enqueue_scripts', 'ajax_enqueue_scripts_create_shipment' );
    2428
    2529
    26 add_action('admin_enqueue_scripts', 'ajax_enqueue_scripts_create_shipment');
     30    // process ajax request
     31    function shipbubble_initiate_order_shipment() {
     32
     33        // check nonce
     34        check_ajax_referer( 'ajax_wc_admin', 'nonce' );
     35
     36        // check user
     37        if ( ! current_user_can( 'manage_options' ) ) return;
     38
     39        $orderId = sanitize_text_field( $_POST['data']['order_id'] );
     40
     41        // get shipment details
     42        $shipmentPayload = unserialize(get_post_meta($orderId, 'shipbubble_shipment_details')[0]);
     43
     44        // set time meta to initiate the request
     45        $shipmentPayload['admin_initiate_shipment_time'] = date('Y-m-d H:i:s');
     46        update_post_meta($orderId, 'shipbubble_shipment_details', serialize($shipmentPayload));
    2747
    2848
    29 // process ajax request
    30 function shipbubble_initiate_order_shipment()
    31 {
     49        if (isset($shipmentPayload) && !empty($shipmentPayload['request_token']) && !empty($shipmentPayload['courier_id']) && !empty($shipmentPayload['service_code'])) {
     50            // initiate request
     51            $response = shipbubble_create_shipment($shipmentPayload);
     52        } else {
     53            $checkoutPayload = unserialize(get_post_meta($orderId, 'sb_shipment_meta')[0]);
    3254
    33     // check nonce
    34     check_ajax_referer('ajax_wc_admin', 'nonce');
     55            // TODO: check token expiry
     56            if (empty($shipmentPayload['request_token'])) {
     57                $shipmentPayload['request_token'] = $checkoutPayload['shipment_payload']['request_token'] ?? '';
     58            }
    3559
    36     // check user
    37     if (!current_user_can('manage_options')) return;
     60            if (empty($shipmentPayload['courier_id'])) {
     61                $shipmentPayload['courier_id'] = $checkoutPayload['shipment_payload']['courier_id'] ?? '';
     62            }
     63            if (empty($shipmentPayload['service_code'])) {
     64                $shipmentPayload['service_code'] = $checkoutPayload['shipment_payload']['service_code'] ?? '';
     65            }
    3866
    39     $orderId = sanitize_text_field($_POST['data']['order_id']);
     67            $shipmentPayload['swap_occurred'] = true;
    4068
    41     // get shipment details
    42     $shipmentPayload = unserialize(get_post_meta($orderId, 'shipbubble_shipment_details')[0]);
    43 
    44     // set time meta to initiate the request
    45     $shipmentPayload['admin_initiate_shipment_time'] = date('Y-m-d H:i:s');
    46     update_post_meta($orderId, 'shipbubble_shipment_details', serialize($shipmentPayload));
     69            // initiate request
     70            $response = shipbubble_create_shipment($shipmentPayload);
     71        }
    4772
    4873
    49     if (isset($shipmentPayload) && !empty($shipmentPayload['request_token']) && !empty($shipmentPayload['courier_id']) && !empty($shipmentPayload['service_code'])) {
    50         // initiate request
    51         $response = shipbubble_create_shipment($shipmentPayload);
    52     } else {
    53         $checkoutPayload = unserialize(get_post_meta($orderId, 'sb_shipment_meta')[0]);
     74        if (isset($response->response_code) && $response->response_code == SHIPBUBBLE_RESPONSE_IS_OK)
     75        {
     76            // set shipbubble order id
     77            update_post_meta( $orderId, 'shipbubble_order_id', $response->data->order_id );
    5478
    55         // TODO: check token expiry
    56         if (empty($shipmentPayload['request_token'])) {
    57             $shipmentPayload['request_token'] = $checkoutPayload['shipment_payload']['request_token'] ?? '';
     79            // set time meta
     80            $shipmentPayload['admin_create_shipment_time'] = date('Y-m-d H:i:s');
     81            update_post_meta($orderId, 'shipbubble_shipment_details', serialize($shipmentPayload));
     82
     83            // set shipping status
     84            update_post_meta( $orderId, 'shipbubble_tracking_status', 'pending' );
    5885        }
    5986
    60         if (empty($shipmentPayload['courier_id'])) {
    61             $shipmentPayload['courier_id'] = $checkoutPayload['shipment_payload']['courier_id'] ?? '';
    62         }
    63         if (empty($shipmentPayload['service_code'])) {
    64             $shipmentPayload['service_code'] = $checkoutPayload['shipment_payload']['service_code'] ?? '';
    65         }
     87        echo json_encode($response);
     88       
     89        // end processing
     90        wp_die();
    6691
    67         $shipmentPayload['swap_occurred'] = true;
    68 
    69         // initiate request
    70         $response = shipbubble_create_shipment($shipmentPayload);
    7192    }
    7293
    73 
    74     if (isset($response->response_code) && $response->response_code == SHIPBUBBLE_RESPONSE_IS_OK) {
    75         // set shipbubble order id
    76         update_post_meta($orderId, 'shipbubble_order_id', $response->data->order_id);
    77 
    78         // set time meta
    79         $shipmentPayload['admin_create_shipment_time'] = date('Y-m-d H:i:s');
    80         update_post_meta($orderId, 'shipbubble_shipment_details', serialize($shipmentPayload));
    81 
    82         // set shipping status
    83         update_post_meta($orderId, 'shipbubble_tracking_status', 'pending');
    84     }
    85 
    86     echo json_encode($response);
    87 
    88     // end processing
    89     wp_die();
    90 }
    91 
    92 // ajax hook for logged-in users: wp_ajax_{action}
    93 add_action('wp_ajax_initiate_order_shipment', 'shipbubble_initiate_order_shipment');
     94    // ajax hook for logged-in users: wp_ajax_{action}
     95    add_action( 'wp_ajax_initiate_order_shipment', 'shipbubble_initiate_order_shipment' );
  • shipbubble/trunk/admin/woocommerce/shipping-settings.php

    r2964989 r3101414  
    11<?php // Shipbubble woocommerce shipping settings
    22
    3 /**
    4  * Check if WooCommerce is active
    5  */
    6 if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
    7     function shipbubble_shipping_service_init()
     3    /**
     4     * Check if WooCommerce is active
     5     */
     6    if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
    87    {
    9         if (!class_exists('WC_SHIPBUBBLE_SHIPPING_METHOD')) {
    10             class WC_SHIPBUBBLE_SHIPPING_METHOD extends WC_Shipping_Method
    11             {
    12                 /**
    13                  * Constructor for your shipping class
    14                  *
    15                  * @access public
    16                  * @return void
    17                  */
    18                 public function __construct()
     8        function shipbubble_shipping_service_init()
     9        {
     10            if ( ! class_exists( 'WC_SHIPBUBBLE_SHIPPING_METHOD' ) )  {
     11                class WC_SHIPBUBBLE_SHIPPING_METHOD extends WC_Shipping_Method
    1912                {
    20                     $this->id                 = SHIPBUBBLE_ID; // Id for your shipping method. Should be uunique.
    21                     $this->method_title       = __('Shipbubble');  // Title shown in admin
     13                    /**
     14                     * Constructor for your shipping class
     15                     *
     16                     * @access public
     17                     * @return void
     18                     */
     19                    public function __construct()
     20                    {
     21                        $this->id                 = SHIPBUBBLE_ID; // Id for your shipping method. Should be uunique.
     22                        $this->method_title       = __( 'Shipbubble' );  // Title shown in admin
     23                       
     24                        $this->method_description = __( '' ); // Description shown in admin
    2225
    23                     $this->method_description = __(''); // Description shown in admin
     26                        // Define user set variables
     27                        $this->enabled            = $this->get_option('activate_shipbubble', 'no'); // This can be added as an setting but for this example its forced enabled
     28                        $this->title              = "Shipbubble"; // This can be added as an setting but for this example its forced.
    2429
    25                     // Define user set variables
    26                     $this->enabled            = $this->get_option('activate_shipbubble', 'no'); // This can be added as an setting but for this example its forced enabled
    27                     $this->title              = "Shipbubble"; // This can be added as an setting but for this example its forced.
    28 
    29                     $this->init();
    30                 }
    31 
    32                 /**
    33                  * Init your settings
    34                  *
    35                  * @access public
    36                  * @return void
    37                  */
    38                 public function init()
    39                 {
    40 
    41                     $this->display_errors();
    42 
    43                     $response = shipbubble_get_wallet_balance(shipbubble_get_token());
    44 
    45                     // Load the settings API
    46                     if (isset($response->response_code) && $response->response_code == SHIPBUBBLE_RESPONSE_IS_OK) {
    47                         $this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings
     30                        $this->init();
    4831                    }
    4932
    50                     $this->init_settings(); // This is part of the settings API. Loads settings you previously init.
     33                    /**
     34                     * Init your settings
     35                     *
     36                     * @access public
     37                     * @return void
     38                     */
     39                    public function init()
     40                    {
     41
     42                        $this->display_errors();
     43
     44                        $response = shipbubble_get_wallet_balance(shipbubble_get_token());
     45   
     46                        // Load the settings API
     47                        if (isset($response->response_code) && $response->response_code == SHIPBUBBLE_RESPONSE_IS_OK) {
     48                            $this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings
     49                        }
     50
     51                        $this->init_settings(); // This is part of the settings API. Loads settings you previously init.
    5152
    5253
    53                     // Save settings in admin if you have any defined
    54                     add_action('woocommerce_update_options_shipping_' . $this->id, array($this, 'process_admin_options'));
    55                 }
     54                        // Save settings in admin if you have any defined
     55                        add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
     56                    }
    5657
    57                 public function init_form_fields()
    58                 {
    59                     $countries_obj   = new WC_Countries();
    60                     $countries   = $countries_obj->__get('countries');
    61                     $default_country = $countries_obj->get_base_country();
     58                    public function init_form_fields()
     59                    {
     60                        $countries_obj   = new WC_Countries();
     61                        $countries   = $countries_obj->__get('countries');
     62                        $default_country = $countries_obj->get_base_country();
     63                       
     64                        // $courier_options = shipbubble_courier_options();
     65                        $categories_options = shipbubble_get_order_categories();
    6266
    63                     // $courier_options = shipbubble_courier_options();
    64                     $categories_options = shipbubble_get_order_categories();
     67                        // $isEnabled = '<br><div class="sb-activated-not">Not Activated for use</div>';
     68                        // if ($this->get_option('activate_shipbubble', 'no') == 'yes') {
     69                        //     $isEnabled = '<br><div class="sb-activated-success">Activated for use</div>';
     70                        // }
    6571
    66                     // $isEnabled = '<br><div class="sb-activated-not">Not Activated for use</div>';
    67                     // if ($this->get_option('activate_shipbubble', 'no') == 'yes') {
    68                     //     $isEnabled = '<br><div class="sb-activated-success">Activated for use</div>';
    69                     // }
     72                        // $this->method_description .= $isEnabled;
    7073
    71                     // $this->method_description .= $isEnabled;
     74                        $this->form_fields = array(
     75                            'activate_shipbubble' => array(
     76                                'title'         => __( 'Activate to use', 'woocommerce' ),
     77                                'type'             => 'checkbox',
     78                                'description'     => __( 'Activate Shipubble on Checkout.', 'woocommerce' ),
     79                                'default'        => __( 'no', 'woocommerce' ),
     80                            ),
     81                            'sender_name' => array(
     82                                'title'         => __( 'Sender\'s Name', 'woocommerce' ),
     83                                'type'             => 'text',
     84                                'class' => 'address_form_field',
     85                                'description'     => __( 'This is the first and last name of the sender sender.', 'woocommerce' ),
     86                                'placeholder'        => __( 'Store Sender Name', 'woocommerce' ),
     87                            ),
     88                            'sender_phone' => array(
     89                                'title'         => __( 'Sender\'s Phone Number', 'woocommerce' ),
     90                                'type'             => 'text',
     91                                'class' => 'address_form_field',
     92                                'description'     => __( 'This is the phone number of the sender.', 'woocommerce' ),
     93                            ),
     94                            'sender_email' => array(
     95                                'title'         => __( 'Sender\'s Email Address', 'woocommerce' ),
     96                                'type'             => 'text',
     97                                'class' => 'address_form_field',
     98                                'description'     => __( 'This is the email of the sender.', 'woocommerce' ),
     99                            ),
     100                            'pickup_address' => array(
     101                                'title'         => __( 'Sender Address', 'woocommerce' ),
     102                                'type'             => 'text',
     103                                'class' => 'address_form_field',
     104                                'description'     => __( 'This is the address setup for pickup.', 'woocommerce' ),
     105                                'default'        => __( '', 'woocommerce' ),
     106                                // 'custom_attributes' => array('readonly' => 'readonly')
     107                            ),
     108                            'pickup_state' => array(
     109                                'title'         => __( 'Sender State', 'woocommerce' ),
     110                                'type'             => 'text',
     111                                'class' => 'address_form_field',
     112                            ),
     113                            'pickup_country' => array(
     114                                'title'         => __( 'Sender Country', 'woocommerce' ),
     115                                'type'             => 'select',
     116                                'class' => 'address_form_field',
     117                                'options' => $countries,
     118                                'default'        => __( $default_country, 'woocommerce' ),
     119                            ),
     120                            'store_category' => array(
     121                                'title'         => __( 'Store Category', 'woocommerce' ),
     122                                'type'             => 'select',
     123                                'options' => $categories_options,
     124                                'custom_attributes' => array('required' => 'required')
     125                                // 'default'        => __( '', 'woocommerce' ),
     126                            ),
     127                            'disable_other_shipping_methods' => array(
     128                                'title'         => __( 'Disable Other Shipping Method', 'woocommerce' ),
     129                                'type'             => 'checkbox',
     130                                'description'     => __( 'Shipbubble will disable other shipping methods.', 'woocommerce' ),
     131                                'default'        => __( 'no', 'woocommerce' ),
     132                            ),
     133                            'address_code' => array(
     134                                // 'title'         => __( 'Address Code', 'woocommerce' ),
     135                                'type'             => 'hidden',
     136                                // 'description'     => __( 'This is the address code setup for pickup (66502255).', 'woocommerce' ),
     137                                'default'        => __( '0', 'woocommerce' ),
     138                                // 'custom_attributes' => array('readonly' => 'readonly')
     139                            ),
     140                        );
     141                       
     142                    }
    72143
    73                     $this->form_fields = array(
    74                         'activate_shipbubble' => array(
    75                             'title'         => __('Activate to use', 'woocommerce'),
    76                             'type'             => 'checkbox',
    77                             'description'     => __('Activate Shipubble on Checkout.', 'woocommerce'),
    78                             'default'        => __('no', 'woocommerce'),
    79                         ),
    80                         'sender_name' => array(
    81                             'title'         => __('Sender\'s Name', 'woocommerce'),
    82                             'type'             => 'text',
    83                             'class' => 'address_form_field',
    84                             'description'     => __('This is the first and last name of the sender sender.', 'woocommerce'),
    85                             'placeholder'        => __('Store Sender Name', 'woocommerce'),
    86                         ),
    87                         'sender_phone' => array(
    88                             'title'         => __('Sender\'s Phone Number', 'woocommerce'),
    89                             'type'             => 'text',
    90                             'class' => 'address_form_field',
    91                             'description'     => __('This is the phone number of the sender.', 'woocommerce'),
    92                         ),
    93                         'sender_email' => array(
    94                             'title'         => __('Sender\'s Email Address', 'woocommerce'),
    95                             'type'             => 'text',
    96                             'class' => 'address_form_field',
    97                             'description'     => __('This is the email of the sender.', 'woocommerce'),
    98                         ),
    99                         'pickup_address' => array(
    100                             'title'         => __('Sender Address', 'woocommerce'),
    101                             'type'             => 'text',
    102                             'class' => 'address_form_field',
    103                             'description'     => __('This is the address setup for pickup.', 'woocommerce'),
    104                             'default'        => __('', 'woocommerce'),
    105                             // 'custom_attributes' => array('readonly' => 'readonly')
    106                         ),
    107                         'pickup_state' => array(
    108                             'title'         => __('Sender State', 'woocommerce'),
    109                             'type'             => 'text',
    110                             'class' => 'address_form_field',
    111                         ),
    112                         'pickup_country' => array(
    113                             'title'         => __('Sender Country', 'woocommerce'),
    114                             'type'             => 'select',
    115                             'class' => 'address_form_field',
    116                             'options' => $countries,
    117                             'default'        => __($default_country, 'woocommerce'),
    118                         ),
    119                         'store_category' => array(
    120                             'title'         => __('Store Category', 'woocommerce'),
    121                             'type'             => 'select',
    122                             'options' => $categories_options,
    123                             'custom_attributes' => array('required' => 'required')
    124                             // 'default'        => __( '', 'woocommerce' ),
    125                         ),
    126                         'disable_other_shipping_methods' => array(
    127                             'title'         => __('Disable Other Shipping Method', 'woocommerce'),
    128                             'type'             => 'checkbox',
    129                             'description'     => __('Shipbubble will disable other shipping methods.', 'woocommerce'),
    130                             'default'        => __('no', 'woocommerce'),
    131                         ),
    132                         'address_code' => array(
    133                             // 'title'         => __( 'Address Code', 'woocommerce' ),
    134                             'type'             => 'hidden',
    135                             // 'description'     => __( 'This is the address code setup for pickup (66502255).', 'woocommerce' ),
    136                             'default'        => __('0', 'woocommerce'),
    137                             // 'custom_attributes' => array('readonly' => 'readonly')
    138                         ),
    139                     );
    140                 }
     144                    /**
     145                     * calculate_shipping function.
     146                     *
     147                     * @access public
     148                     * @param array $package optional – multi-dimensional array of cart items to calc shipping for.
     149                     * @return void
     150                     */
     151                    public function calculate_shipping( $package = array() )
     152                    {
     153                        // This is where you'll add your rates
     154                        $rate = array(
     155                            'id'     => $this->id,
     156                            'label' => $this->title,
     157                            'cost' => '50000',
     158                            // 'calc_tax' => 'per_item'
     159                        );
     160                        // This will add custom cost to shipping method
    141161
    142                 /**
    143                  * calculate_shipping function.
    144                  *
    145                  * @access public
    146                  * @param array $package optional – multi-dimensional array of cart items to calc shipping for.
    147                  * @return void
    148                  */
    149                 public function calculate_shipping($package = array())
    150                 {
    151                     // This is where you'll add your rates
    152                     $rate = array(
    153                         'id'     => $this->id,
    154                         'label' => $this->title,
    155                         'cost' => '50000',
    156                         // 'calc_tax' => 'per_item'
    157                     );
    158                     // This will add custom cost to shipping method
    159 
    160                     // Register the rate
    161                     $this->add_rate($rate);
     162                        // Register the rate
     163                        $this->add_rate( $rate );
     164                    }
    162165                }
    163166            }
    164167        }
     168
     169        add_action( 'woocommerce_shipping_init', 'shipbubble_shipping_service_init' );
     170
     171        function shipbubble_couriers_methods( $methods )
     172        {
     173            $methods['shipbubble_shipping_services'] = 'WC_SHIPBUBBLE_SHIPPING_METHOD';
     174            return $methods;
     175        }
     176
     177        add_filter( 'woocommerce_shipping_methods', 'shipbubble_couriers_methods' );
    165178    }
    166 
    167     add_action('woocommerce_shipping_init', 'shipbubble_shipping_service_init');
    168 
    169     function shipbubble_couriers_methods($methods)
    170     {
    171         $methods['shipbubble_shipping_services'] = 'WC_SHIPBUBBLE_SHIPPING_METHOD';
    172         return $methods;
    173     }
    174 
    175     add_filter('woocommerce_shipping_methods', 'shipbubble_couriers_methods');
    176 }
  • shipbubble/trunk/includes/core-methods.php

    r3041186 r3101414  
    185185
    186186        // Get the currency symbol for the specified currency code
    187         // $currency_symbol = get_woocommerce_currency_symbol($currency_code);
     187        $currency_symbol = get_woocommerce_currency_symbol($currency_code);
    188188        // $rates['currency_symbol'] = $currency_symbol;
    189 
    190         $rates['currency_symbol'] = $currency_code;
     189       
     190        $rates['currency_symbol'] = $currency_symbol;
    191191    } else {
    192192        if (isset($response->error)) {
     
    375375    return is_string($str) && ($str == serialize(false) || @unserialize($str) !== false);
    376376}
     377
     378function shipbubble_get_currency_code() {
     379    if (class_exists('YITH_WCMCS_Currency_Handler')) {
     380        $currency_code = yith_wcmcs_get_current_currency_id();
     381    } else {
     382        $currency_code = get_woocommerce_currency();
     383    }
     384
     385    return empty($currency_code) ? 'NGN' : $currency_code;
     386}
  • shipbubble/trunk/includes/endpoints.php

    r3027148 r3101414  
    313313    }
    314314
     315
    315316    $setDimensions = shipbubble_set_package_dimensions($netWeight);
    316317
     
    318319    $categoryCode = get_option(WC_SHIPBUBBLE_ID)['store_category'];
    319320
    320     // Get the currency code used in the cart
    321     $currency_code = get_woocommerce_currency();
    322 
     321    $currency_code = shipbubble_get_currency_code();
    323322    $payload = [
    324323        'sender_address_code' => $senderAddressCode,
     
    334333        'service_type' => 'pickup',
    335334        'delivery_instructions' => $products['comments'] ?? 'please handle carefully',
     335        'store_checkout_currency' => $currency_code
    336336    ];
    337 
    338     if (!empty($currency_code)) {
    339         $payload['store_checkout_currency'] = $currency_code;
    340     }
    341 
    342     // error_log(print_r($payload, true));
    343337
    344338    // return json_decode(json_encode($payload));
  • shipbubble/trunk/public/async-checkout-couriers.php

    r2955081 r3101414  
    11<?php // Silence is Golden
    22
    3 // enqueue scripts
    4 function ajax_public_enqueue_scripts($hook)
    5 {
     3    // enqueue scripts
     4    function ajax_public_enqueue_scripts( $hook ) {
    65
    7     // check if our page
     6        // check if our page
    87
    9     if ('' !== $hook) return;
     8        if ( '' !== $hook ) return;
    109
    11     // define script url
    12     $script_url = plugins_url('/js/couriers-on-checkout.js', __FILE__);
     10        // define script url
     11        $script_url = plugins_url( '/js/couriers-on-checkout.js', __FILE__ );
    1312
    14     // enqueue script
    15     wp_enqueue_script('ajax-public', $script_url, array('jquery'));
     13        // enqueue script
     14        wp_enqueue_script( 'ajax-public', $script_url, array( 'jquery' ) );
    1615
    17     // create nonce
    18     $nonce = wp_create_nonce('ajax_public');
     16        // create nonce
     17        $nonce = wp_create_nonce( 'ajax_public' );
    1918
    20     // define ajax url
    21     $ajax_url = admin_url('admin-ajax.php');
     19        // define ajax url
     20        $ajax_url = admin_url( 'admin-ajax.php' );
    2221
    23     // define script
    24     $script = array('nonce' => $nonce, 'ajaxurl' => $ajax_url);
     22        // define script
     23        $script = array( 'nonce' => $nonce, 'ajaxurl' => $ajax_url );
    2524
    26     // localize script
    27     wp_localize_script('ajax-public', 'ajax_public', $script);
    28 }
    29 add_action('wp_enqueue_scripts', 'ajax_public_enqueue_scripts');
     25        // localize script
     26        wp_localize_script( 'ajax-public', 'ajax_public', $script );
     27    }
     28    add_action( 'wp_enqueue_scripts', 'ajax_public_enqueue_scripts' );
    3029
    3130
    32 // process ajax request
    33 function shipbubble_request_shipping_rates()
    34 {
     31    // process ajax request
     32    function shipbubble_request_shipping_rates() {
    3533
    36     // check nonce
    37     check_ajax_referer('ajax_public', 'nonce');
     34        // check nonce
     35        check_ajax_referer( 'ajax_public', 'nonce' );
    3836
    39     $output = array();
     37        $output = array();
    4038
    41     // Any of the WordPress data sanitization functions can be used here
    42     $postData = array_map('sanitize_text_field', $_POST['data']);
     39        // Any of the WordPress data sanitization functions can be used here
     40        $postData = array_map( 'sanitize_text_field', $_POST['data'] );
    4341
    44     $data = isset($postData) ? (array) $postData : array();
     42        $data = isset( $postData ) ? (array) $postData : array();
    4543
    46     // error_log(print_r($data, true));
     44        // error_log(print_r($data, true));
    4745
    48     // Any of the WordPress data sanitization functions can be used here
     46        // Any of the WordPress data sanitization functions can be used here
    4947
    50     if (empty($_POST['data']) || empty($data['name'])  || empty($data['email']) || empty($data['phone']) || empty($data['address'])) {
     48        if ( empty($_POST['data']) || empty($data['name'])  || empty($data['email']) || empty($data['phone']) || empty($data['address']) ) {
    5149
    52         $output = array('status' => 'failed', 'message' => 'Please check your billing / shipping information for all required details');
    53 
    54         echo json_encode($output);
    55     } else {
    56         // validate address
    57         $addressResponse = shipbubble_validate_address(
    58             sanitize_text_field($data['name']),
    59             sanitize_email($data['email']),
    60             sanitize_text_field($data['phone']),
    61             sanitize_text_field($data['address'])
    62         );
    63 
    64         // successful
    65         if (isset($addressResponse->response_code) && $addressResponse->response_code == SHIPBUBBLE_RESPONSE_IS_OK) {
    66             $products = shipbubble_get_checkout_orders();
    67             $products['comments'] = !empty($data['comments']) ? $data['comments'] : 'please handle carefully';
    68             $addressCode = $addressResponse->data->address_code;
    69             $output = array();
    70 
    71             $rates = shipbubble_process_shipping_rates($addressCode, $products);
    72 
    73             if (!isset($rates['error'])) {
    74                 $output = array('status' => 'success', 'data' => $rates);
    75             } else {
    76                 $output = array('status' => 'failed', 'data' => $rates['error']);
    77             }
     50            $output = array('status' => 'failed', 'message' => 'Please check your billing / shipping information for all required details');
    7851
    7952            echo json_encode($output);
    80             wp_die();
    8153        } else {
    82             echo json_encode($addressResponse);
     54            // validate address
     55            $addressResponse = shipbubble_validate_address(
     56                sanitize_text_field($data['name']),
     57                sanitize_email($data['email']),
     58                sanitize_text_field($data['phone']),
     59                sanitize_text_field($data['address'])
     60            );
     61
     62            // successful
     63            if (isset($addressResponse->response_code) && $addressResponse->response_code == SHIPBUBBLE_RESPONSE_IS_OK) {
     64                $products = shipbubble_get_checkout_orders();
     65                $products['comments'] = !empty($data['comments']) ? $data['comments'] : 'please handle carefully';
     66                $addressCode = $addressResponse->data->address_code;
     67                $output = array();
     68
     69                $rates = shipbubble_process_shipping_rates($addressCode, $products);
     70
     71                if (!isset($rates['error'])) {
     72                    $output = array('status' => 'success', 'data' => $rates);
     73                } else {
     74                    $output = array('status' => 'failed', 'data' => $rates['error']);
     75                }
     76               
     77                echo json_encode($output);
     78                wp_die();
     79            } else {
     80                echo json_encode($addressResponse);
     81            }
    8382        }
     83
     84        // end processing
     85        wp_die();
    8486    }
    8587
    86     // end processing
    87     wp_die();
    88 }
    89 
    90 // ajax hook for logged-in users: wp_ajax_{action}
    91 add_action('wp_ajax_request_shipping_rates', 'shipbubble_request_shipping_rates');
    92 add_action('wp_ajax_nopriv_request_shipping_rates', 'shipbubble_request_shipping_rates');
     88    // ajax hook for logged-in users: wp_ajax_{action}
     89    add_action( 'wp_ajax_request_shipping_rates', 'shipbubble_request_shipping_rates' );
     90    add_action( 'wp_ajax_nopriv_request_shipping_rates', 'shipbubble_request_shipping_rates' );
  • shipbubble/trunk/public/css/styles-wc.css

    r2973326 r3101414  
    1 .container-card>button {
     1.container-card > button {
    22    font-weight: 400;
    33    font-size: 16px;
  • shipbubble/trunk/public/woocommerce/checkout.php

    r3012908 r3101414  
    77
    88    $isShipbubbleActive = isset($options['activate_shipbubble']) ? sanitize_text_field($options['activate_shipbubble']) : 'no';
    9 
     9   
    1010    $container = '';
    1111    $btnColor = '';
     
    1717
    1818    // Check if any product in the cart is virtual
    19     foreach (WC()->cart->get_cart() as $cart_item) {
     19    foreach (WC()->cart->get_cart() as $cart_item) {
    2020        $product_id = $cart_item['product_id'];
    21         $product = wc_get_product($product_id);
     21        $product = wc_get_product($product_id);
    2222
    2323        if ($product && $product->is_virtual()) {
     
    2727            $isPhysicalProduct = true;
    2828        }
    29     }
    30 
     29    }
     30   
    3131    if ($isPhysicalProduct) {
    3232        $response = shipbubble_get_color_code();
     
    3535            $showLabel = (bool) $response->data->powered_by_label;
    3636        }
    37 
     37   
    3838        if ($isShipbubbleActive == 'yes') {
    3939            $container .= '
     
    5959                    </div>
    6060                ';
    61 
     61   
    6262            if ($showLabel) {
    6363                $container .= '
     
    7373                $container .= '<div style="margin: 8px 0;"></div>';
    7474            }
    75 
     75   
    7676            $container .= '</div>';
    7777        }
     
    130130                    });
    131131
    132                     $('div#customer_details').on('change', 'input[name^="billing"], input[name^="shipping"]', function() {
     132                    $('div#customer_details').on('change', 'input[name^="billing"], input[name^="shipping"]', function(){
    133133
    134134                        let list = $('#courier-list');
     
    143143                            // set flag that previously set courier should be removed
    144144                            $('#shipbubble_courier_set').val('false');
    145 
     145                           
    146146                            list.empty();
    147147                        }
     
    237237    $shippingMethodKey = SHIPBUBBLE_ID;
    238238    if (isset($rates[$shippingMethodKey])) {
    239         $rates1[$shippingMethodKey] = $rates[$shippingMethodKey];
    240         unset($rates[$shippingMethodKey]);
    241     }
     239        $rates1[$shippingMethodKey] = $rates[$shippingMethodKey];
     240        unset($rates[$shippingMethodKey]);
     241    }
    242242    // select shipbubble on checkout
    243     WC()->session->set('chosen_shipping_methods', [$shippingMethodKey]);
    244 
    245     return isset($rates1) ? array_merge($rates1, $rates) : $rates;
     243    WC()->session->set( 'chosen_shipping_methods', [$shippingMethodKey] );
     244
     245    return isset($rates1) ? array_merge($rates1, $rates) : $rates;
    246246}
    247247
  • shipbubble/trunk/readme.txt

    r3082893 r3101414  
    44Tags: logistics, deliveries, shipping rates, multiple couriers, post-purchase experience
    55Requires at least: 4.0
    6 Tested up to: 6.3
    7 Stable tag: 2.4
     6Tested up to: 6.5
     7Stable tag: 2.4.1
    88Requires PHP: 5.6
    99License: GPLv3 or later
     
    1212== Description ==
    1313
    14 Shipbubble shipping platform that enables retailers to conveniently delight their customers with multiple shipping options and a branded tracking experience thereby increasing conversion rates.
     14Shipbubble is a shipping platform that enables retailers to conveniently delight their customers with multiple shipping options and a branded tracking experience thereby increasing conversion rates.
    1515
    1616[youtube https://www.youtube.com/watch?v=eGxMxB0QbXc]
     
    5151
    5252== Changelog ==
     53= 2.4.1 =
     54* Free shipping at checkout fix and currency converter optimizer
     55
    5356= 2.4 =
    5457* Critical checkoutand backend dashboard fixes
     
    118121
    119122== Upgrade Notice ==
    120 = 2.4 =
    121 Critical checkout and backend dashboard fixes
     123= 2.4.1 =
     124Free shipping at checkout fix and currency converter optimizer.
  • shipbubble/trunk/shipbubble.php

    r3082893 r3101414  
    88 * Tags: logistics, deliveries, shipping rates, multiple couriers, post purchase experience
    99 * Requires at least: 4.0
    10  * Tested up to: 6.1
    11  * Version: 2.4
     10 * Tested up to: 6.5
     11 * Version: 2.4.1
    1212 * Requires PHP: 5.6
    1313 * Text Domain:  shipbubble
     
    381381        if (in_array($payment_method, $enabled_gateways)) {
    382382            // check shipping items is empty or shipping total is 0
    383             if (empty($shipping_items) || $shipping_total == "0") {
    384                 $delete_order = true;
    385                 error_log(print_r('empty or 0', true));
    386             }
    387 
    388             // check that shipbubble is in use and shipping total is 0
    389             if (!empty($chosen_shipping_method) && $chosen_shipping_method[0] == SHIPBUBBLE_ID && $shipping_total == "0") {
     383            if (empty($shipping_items) || (!empty($chosen_shipping_method) && $chosen_shipping_method[0] == SHIPBUBBLE_ID && $shipping_total == "0")) {
    390384                $delete_order = true;
    391385                error_log(print_r('selected sb & 0', true));
Note: See TracChangeset for help on using the changeset viewer.