Changeset 3101414
- Timestamp:
- 06/11/2024 08:37:44 PM (21 months ago)
- Location:
- shipbubble
- Files:
-
- 45 added
- 9 edited
-
tags/2.4.1 (added)
-
tags/2.4.1/admin (added)
-
tags/2.4.1/admin/css (added)
-
tags/2.4.1/admin/css/styles-wc.css (added)
-
tags/2.4.1/admin/index.php (added)
-
tags/2.4.1/admin/js (added)
-
tags/2.4.1/admin/js/ajax-create-shipment.js (added)
-
tags/2.4.1/admin/js/ajax-validate-address.js (added)
-
tags/2.4.1/admin/js/ajax-validate-auth.js (added)
-
tags/2.4.1/admin/woocommerce (added)
-
tags/2.4.1/admin/woocommerce/async-create-shipment.php (added)
-
tags/2.4.1/admin/woocommerce/async-validate-address.php (added)
-
tags/2.4.1/admin/woocommerce/enqueue-styles.php (added)
-
tags/2.4.1/admin/woocommerce/orders.php (added)
-
tags/2.4.1/admin/woocommerce/shipping-settings.php (added)
-
tags/2.4.1/admin/wordpress (added)
-
tags/2.4.1/admin/wordpress/async-validate-auth.php (added)
-
tags/2.4.1/admin/wordpress/index.php (added)
-
tags/2.4.1/admin/wordpress/settings-callback.php (added)
-
tags/2.4.1/admin/wordpress/settings-field-validation.php (added)
-
tags/2.4.1/admin/wordpress/settings-menu.php (added)
-
tags/2.4.1/admin/wordpress/settings-page.php (added)
-
tags/2.4.1/admin/wordpress/settings-register.php (added)
-
tags/2.4.1/includes (added)
-
tags/2.4.1/includes/constants.php (added)
-
tags/2.4.1/includes/core-methods.php (added)
-
tags/2.4.1/includes/endpoints.php (added)
-
tags/2.4.1/includes/index.php (added)
-
tags/2.4.1/index.php (added)
-
tags/2.4.1/languages (added)
-
tags/2.4.1/languages/index.php (added)
-
tags/2.4.1/license.txt (added)
-
tags/2.4.1/public (added)
-
tags/2.4.1/public/async-checkout-couriers.php (added)
-
tags/2.4.1/public/css (added)
-
tags/2.4.1/public/css/styles-wc.css (added)
-
tags/2.4.1/public/js (added)
-
tags/2.4.1/public/js/couriers-on-checkout.js (added)
-
tags/2.4.1/public/js/sweetalert2.min.js (added)
-
tags/2.4.1/public/woocommerce (added)
-
tags/2.4.1/public/woocommerce/checkout.php (added)
-
tags/2.4.1/public/woocommerce/enqueue-styles.php (added)
-
tags/2.4.1/readme.txt (added)
-
tags/2.4.1/shipbubble.php (added)
-
tags/2.4.1/uninstall.php (added)
-
trunk/admin/woocommerce/async-create-shipment.php (modified) (1 diff)
-
trunk/admin/woocommerce/shipping-settings.php (modified) (1 diff)
-
trunk/includes/core-methods.php (modified) (2 diffs)
-
trunk/includes/endpoints.php (modified) (3 diffs)
-
trunk/public/async-checkout-couriers.php (modified) (1 diff)
-
trunk/public/css/styles-wc.css (modified) (1 diff)
-
trunk/public/woocommerce/checkout.php (modified) (9 diffs)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/shipbubble.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shipbubble/trunk/admin/woocommerce/async-create-shipment.php
r3010288 r3101414 1 1 <?php 2 2 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__ ) ); 8 11 9 // define script url10 $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' ) ); 11 14 12 // enqueue script13 wp_enqueue_script('ajax-wc-admin', $script_url, array('jquery'));15 // create nonce 16 $nonce = wp_create_nonce( 'ajax_wc_admin' ); 14 17 15 // create nonce16 $nonce = wp_create_nonce('ajax_wc_admin');18 // define script 19 $script = array( 'nonce' => $nonce ); 17 20 18 // define script19 $script = array('nonce' => $nonce);21 // localize script 22 wp_localize_script( 'ajax-wc-admin', 'ajax_wc_admin', $script ); 20 23 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' ); 24 28 25 29 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)); 27 47 28 48 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]); 32 54 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 } 35 59 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 } 38 66 39 $orderId = sanitize_text_field($_POST['data']['order_id']);67 $shipmentPayload['swap_occurred'] = true; 40 68 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 } 47 72 48 73 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 ); 54 78 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' ); 58 85 } 59 86 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(); 66 91 67 $shipmentPayload['swap_occurred'] = true;68 69 // initiate request70 $response = shipbubble_create_shipment($shipmentPayload);71 92 } 72 93 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 1 1 <?php // Shipbubble woocommerce shipping settings 2 2 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' ) ) ) ) 8 7 { 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 19 12 { 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 22 25 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. 24 29 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(); 48 31 } 49 32 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. 51 52 52 53 53 // Save settings in admin if you have any defined54 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 } 56 57 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(); 62 66 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 // } 65 71 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; 70 73 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 } 72 143 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 141 161 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 } 162 165 } 163 166 } 164 167 } 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' ); 165 178 } 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 185 185 186 186 // 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); 188 188 // $rates['currency_symbol'] = $currency_symbol; 189 190 $rates['currency_symbol'] = $currency_ code;189 190 $rates['currency_symbol'] = $currency_symbol; 191 191 } else { 192 192 if (isset($response->error)) { … … 375 375 return is_string($str) && ($str == serialize(false) || @unserialize($str) !== false); 376 376 } 377 378 function 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 313 313 } 314 314 315 315 316 $setDimensions = shipbubble_set_package_dimensions($netWeight); 316 317 … … 318 319 $categoryCode = get_option(WC_SHIPBUBBLE_ID)['store_category']; 319 320 320 // Get the currency code used in the cart 321 $currency_code = get_woocommerce_currency(); 322 321 $currency_code = shipbubble_get_currency_code(); 323 322 $payload = [ 324 323 'sender_address_code' => $senderAddressCode, … … 334 333 'service_type' => 'pickup', 335 334 'delivery_instructions' => $products['comments'] ?? 'please handle carefully', 335 'store_checkout_currency' => $currency_code 336 336 ]; 337 338 if (!empty($currency_code)) {339 $payload['store_checkout_currency'] = $currency_code;340 }341 342 // error_log(print_r($payload, true));343 337 344 338 // return json_decode(json_encode($payload)); -
shipbubble/trunk/public/async-checkout-couriers.php
r2955081 r3101414 1 1 <?php // Silence is Golden 2 2 3 // enqueue scripts 4 function ajax_public_enqueue_scripts($hook) 5 { 3 // enqueue scripts 4 function ajax_public_enqueue_scripts( $hook ) { 6 5 7 // check if our page6 // check if our page 8 7 9 if ('' !== $hook) return;8 if ( '' !== $hook ) return; 10 9 11 // define script url12 $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__ ); 13 12 14 // enqueue script15 wp_enqueue_script('ajax-public', $script_url, array('jquery'));13 // enqueue script 14 wp_enqueue_script( 'ajax-public', $script_url, array( 'jquery' ) ); 16 15 17 // create nonce18 $nonce = wp_create_nonce('ajax_public');16 // create nonce 17 $nonce = wp_create_nonce( 'ajax_public' ); 19 18 20 // define ajax url21 $ajax_url = admin_url('admin-ajax.php');19 // define ajax url 20 $ajax_url = admin_url( 'admin-ajax.php' ); 22 21 23 // define script24 $script = array('nonce' => $nonce, 'ajaxurl' => $ajax_url);22 // define script 23 $script = array( 'nonce' => $nonce, 'ajaxurl' => $ajax_url ); 25 24 26 // localize script27 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' ); 30 29 31 30 32 // process ajax request 33 function shipbubble_request_shipping_rates() 34 { 31 // process ajax request 32 function shipbubble_request_shipping_rates() { 35 33 36 // check nonce37 check_ajax_referer('ajax_public', 'nonce');34 // check nonce 35 check_ajax_referer( 'ajax_public', 'nonce' ); 38 36 39 $output = array();37 $output = array(); 40 38 41 // Any of the WordPress data sanitization functions can be used here42 $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'] ); 43 41 44 $data = isset($postData) ? (array) $postData : array();42 $data = isset( $postData ) ? (array) $postData : array(); 45 43 46 // error_log(print_r($data, true));44 // error_log(print_r($data, true)); 47 45 48 // Any of the WordPress data sanitization functions can be used here46 // Any of the WordPress data sanitization functions can be used here 49 47 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']) ) { 51 49 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'); 78 51 79 52 echo json_encode($output); 80 wp_die();81 53 } 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 } 83 82 } 83 84 // end processing 85 wp_die(); 84 86 } 85 87 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 { 2 2 font-weight: 400; 3 3 font-size: 16px; -
shipbubble/trunk/public/woocommerce/checkout.php
r3012908 r3101414 7 7 8 8 $isShipbubbleActive = isset($options['activate_shipbubble']) ? sanitize_text_field($options['activate_shipbubble']) : 'no'; 9 9 10 10 $container = ''; 11 11 $btnColor = ''; … … 17 17 18 18 // 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) { 20 20 $product_id = $cart_item['product_id']; 21 $product = wc_get_product($product_id);21 $product = wc_get_product($product_id); 22 22 23 23 if ($product && $product->is_virtual()) { … … 27 27 $isPhysicalProduct = true; 28 28 } 29 }30 29 } 30 31 31 if ($isPhysicalProduct) { 32 32 $response = shipbubble_get_color_code(); … … 35 35 $showLabel = (bool) $response->data->powered_by_label; 36 36 } 37 37 38 38 if ($isShipbubbleActive == 'yes') { 39 39 $container .= ' … … 59 59 </div> 60 60 '; 61 61 62 62 if ($showLabel) { 63 63 $container .= ' … … 73 73 $container .= '<div style="margin: 8px 0;"></div>'; 74 74 } 75 75 76 76 $container .= '</div>'; 77 77 } … … 130 130 }); 131 131 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(){ 133 133 134 134 let list = $('#courier-list'); … … 143 143 // set flag that previously set courier should be removed 144 144 $('#shipbubble_courier_set').val('false'); 145 145 146 146 list.empty(); 147 147 } … … 237 237 $shippingMethodKey = SHIPBUBBLE_ID; 238 238 if (isset($rates[$shippingMethodKey])) { 239 $rates1[$shippingMethodKey] = $rates[$shippingMethodKey];240 unset($rates[$shippingMethodKey]);241 }239 $rates1[$shippingMethodKey] = $rates[$shippingMethodKey]; 240 unset($rates[$shippingMethodKey]); 241 } 242 242 // 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; 246 246 } 247 247 -
shipbubble/trunk/readme.txt
r3082893 r3101414 4 4 Tags: logistics, deliveries, shipping rates, multiple couriers, post-purchase experience 5 5 Requires at least: 4.0 6 Tested up to: 6. 37 Stable tag: 2.4 6 Tested up to: 6.5 7 Stable tag: 2.4.1 8 8 Requires PHP: 5.6 9 9 License: GPLv3 or later … … 12 12 == Description == 13 13 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.14 Shipbubble 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. 15 15 16 16 [youtube https://www.youtube.com/watch?v=eGxMxB0QbXc] … … 51 51 52 52 == Changelog == 53 = 2.4.1 = 54 * Free shipping at checkout fix and currency converter optimizer 55 53 56 = 2.4 = 54 57 * Critical checkoutand backend dashboard fixes … … 118 121 119 122 == Upgrade Notice == 120 = 2.4 =121 Critical checkout and backend dashboard fixes 123 = 2.4.1 = 124 Free shipping at checkout fix and currency converter optimizer. -
shipbubble/trunk/shipbubble.php
r3082893 r3101414 8 8 * Tags: logistics, deliveries, shipping rates, multiple couriers, post purchase experience 9 9 * Requires at least: 4.0 10 * Tested up to: 6. 111 * Version: 2.4 10 * Tested up to: 6.5 11 * Version: 2.4.1 12 12 * Requires PHP: 5.6 13 13 * Text Domain: shipbubble … … 381 381 if (in_array($payment_method, $enabled_gateways)) { 382 382 // 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")) { 390 384 $delete_order = true; 391 385 error_log(print_r('selected sb & 0', true));
Note: See TracChangeset
for help on using the changeset viewer.