| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shipping metod Extension. |
| 4 |
* |
| 5 |
* @author Shiprocket |
| 6 |
* |
| 7 |
* @package Shiprocket |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; // exit if directly accessed. |
| 12 |
} |
| 13 |
|
| 14 |
if ( is_admin() && ! empty( $_GET['section'] ) && 'shiprocket_woocommerce_shipping' === $_GET['section'] ) { |
| 15 |
$user_meta = Shiprocket_Shipping_Rates_Common::get_current_user_meta(); |
| 16 |
?> |
| 17 |
<script> |
| 18 |
window.addEventListener('load', function () { |
| 19 |
|
| 20 |
// To create button to get the account details |
| 21 |
let integrationId = jQuery('#woocommerce_shiprocket_woocommerce_shipping_integration_id').val(); |
| 22 |
|
| 23 |
if (integrationId != undefined && integrationId.length == 0) { |
| 24 |
jQuery('.space_before_shiprocket_get_account_details_button').remove(); // To avoid multiple times. |
| 25 |
jQuery('#shiprocket_get_account_details').remove(); // To avoid multiple times. |
| 26 |
|
| 27 |
let createShiprocketAccount = jQuery('<button class="button button-primary" type="button" id="shiprocket_get_account_details" >Signup Shiprocket.in & Get API Keys</button>'); |
| 28 |
|
| 29 |
jQuery("#woocommerce_shiprocket_woocommerce_shipping_phone").after(createShiprocketAccount); // Add button. |
| 30 |
jQuery("#shiprocket_get_account_details").before('<space class="space_before_shiprocket_get_account_details_button"> </space>'); // Add space. |
| 31 |
} |
| 32 |
|
| 33 |
// Call to Shiprocket Server to get the response. |
| 34 |
jQuery("#shiprocket_get_account_details").click(function () { |
| 35 |
var email = jQuery('#woocommerce_shiprocket_woocommerce_shipping_email_id').val(); |
| 36 |
if (email == '') |
| 37 |
{ |
| 38 |
alert("Enter your registered mail id with shiprocket"); |
| 39 |
return false; |
| 40 |
} |
| 41 |
var phone = jQuery('#woocommerce_shiprocket_woocommerce_shipping_phone').val(); |
| 42 |
if (phone == '') |
| 43 |
{ |
| 44 |
alert("Enter your phone"); |
| 45 |
return false; |
| 46 |
} |
| 47 |
var first_name = jQuery('#woocommerce_shiprocket_woocommerce_shipping_first_name').val(); |
| 48 |
if (first_name == '') |
| 49 |
{ |
| 50 |
alert("Enter your first name"); |
| 51 |
return false; |
| 52 |
} |
| 53 |
var last_name = jQuery('#woocommerce_shiprocket_woocommerce_shipping_last_name').val(); |
| 54 |
if (last_name == '') |
| 55 |
{ |
| 56 |
alert("Enter your last name"); |
| 57 |
return false; |
| 58 |
} |
| 59 |
var company_name = jQuery('#woocommerce_shiprocket_woocommerce_shipping_company_name').val(); |
| 60 |
if (company_name == '') |
| 61 |
{ |
| 62 |
alert("Enter your Company name"); |
| 63 |
return false; |
| 64 |
} |
| 65 |
|
| 66 |
jQuery(this).prop("disabled", true); |
| 67 |
|
| 68 |
var token = 'ACCESS_TOKEN:' + '<?php echo esc_html( SOURCE_WC_APP ); ?>'; |
| 69 |
|
| 70 |
let data = {}; |
| 71 |
|
| 72 |
data.email = jQuery('#woocommerce_shiprocket_woocommerce_shipping_email_id').val(); |
| 73 |
data.phone = jQuery('#woocommerce_shiprocket_woocommerce_shipping_phone').val(); |
| 74 |
data.first_name = jQuery('#woocommerce_shiprocket_woocommerce_shipping_first_name').val(); |
| 75 |
data.last_name = jQuery('#woocommerce_shiprocket_woocommerce_shipping_last_name').val(); |
| 76 |
data.company_name = jQuery('#woocommerce_shiprocket_woocommerce_shipping_company_name').val(); |
| 77 |
data.store_url = "<?php echo esc_html( get_site_url() ); ?>"; |
| 78 |
data.storeName = "<?php echo esc_html( bloginfo() ); ?>"; |
| 79 |
data.billing_address = "<?php echo !empty($user_meta['billing_address_1'][0]) ? esc_html( $user_meta['billing_address_1'][0] ) : ''; ?>"; |
| 80 |
data.billing_address_2 = "<?php echo !empty($user_meta['billing_address_2'][0]) ? esc_html( $user_meta['billing_address_2'][0] ) : ''; ?>"; |
| 81 |
data.billing_city = "<?php echo !empty($user_meta['billing_city'][0]) ? esc_html( $user_meta['billing_city'][0] ) : ''; ?>"; |
| 82 |
data.billing_state = "<?php echo !empty($user_meta['billing_state'][0]) ? esc_html( $user_meta['billing_state'][0] ) : ''; ?>"; |
| 83 |
data.billing_country = "<?php echo !empty($user_meta['billing_country'][0]) ? esc_html( $user_meta['billing_country'][0] ) : ''; ?>"; |
| 84 |
data.billing_pin_code = "<?php echo !empty($user_meta['billing_postcode'][0]) ? esc_html( $user_meta['billing_postcode'][0] ) : ''; ?>"; |
| 85 |
data.billing_phone = "<?php echo !empty($user_meta['billing_phone'][0]) ? esc_html( $user_meta['billing_phone'][0] ) : ''; ?>"; |
| 86 |
data.shipping_address = "<?php echo !empty($user_meta['shipping_address_1'][0]) ? esc_html( $user_meta['shipping_address_1'][0] ) : ''; ?>"; |
| 87 |
<?php ob_start(); ?> |
| 88 |
data.shipping_address_2 = "<?php echo !empty($user_meta['shipping_address_2'][0]) ? esc_html( $user_meta['shipping_address_2'][0] ) : ''; ?>"; |
| 89 |
data.shipping_city = "<?php echo !empty($user_meta['shipping_city'][0]) ? esc_html( $user_meta['shipping_city'][0] ) : ''; ?>"; |
| 90 |
data.shipping_state = "<?php echo !empty($user_meta['shipping_state'][0]) ? esc_html( $user_meta['shipping_state'][0] ) : ''; ?>"; |
| 91 |
data.shipping_country = "<?php echo !empty($user_meta['shipping_country'][0]) ? esc_html( $user_meta['shipping_country'][0] ) : ''; ?>"; |
| 92 |
data.shipping_pin_code = "<?php echo !empty($user_meta['shipping_postcode'][0]) ? esc_html( $user_meta['shipping_postcode'][0] ) : ''; ?>"; |
| 93 |
data.shipping_phone = "<?php echo !empty($user_meta['shipping_phone'][0]) ? esc_html( $user_meta['shipping_phone'][0] ) : ''; ?>"; |
| 94 |
|
| 95 |
data.utm_source = "Woocommerce-Marketplace"; |
| 96 |
data.utm_medium = "Referal"; |
| 97 |
data.utm_campaign = "Woocommerce-App-Download"; |
| 98 |
data.utm_content = ""; |
| 99 |
data.utm_term = ""; |
| 100 |
|
| 101 |
jQuery.ajax({ |
| 102 |
url: "<?php echo esc_html( SHIPROCKET_WC_ACCOUNT_REGISTER_ENDPOINT ); ?>", |
| 103 |
data: JSON.stringify(data), |
| 104 |
method: 'POST', |
| 105 |
contentType: 'application/json', |
| 106 |
beforeSend: function (xhr) { |
| 107 |
xhr.setRequestHeader("authorization", token); |
| 108 |
} |
| 109 |
}).done(function (response) { |
| 110 |
if (response.status != 1) { |
| 111 |
alert(response.message); |
| 112 |
} else if (response.status == 1) { |
| 113 |
jQuery("#woocommerce_shiprocket_woocommerce_shipping_integration_id").val(response.merchant_id); |
| 114 |
alert("Shiprocket Account linked successfully!"); |
| 115 |
} |
| 116 |
jQuery('#shiprocket_get_account_details').prop("disabled", false); |
| 117 |
}).fail(function (result) { |
| 118 |
alert('No response from Shiprocket Server. Something Went wrong'); |
| 119 |
jQuery('#shiprocket_get_account_details').prop("disabled", false); |
| 120 |
}); |
| 121 |
}); |
| 122 |
|
| 123 |
|
| 124 |
jQuery(".woocommerce-save-button").off().click(function () { |
| 125 |
if (jQuery('#woocommerce_shiprocket_woocommerce_shipping_realtime_enabled').is(":checked")) { |
| 126 |
var email = jQuery('#woocommerce_shiprocket_woocommerce_shipping_email_id').val(); |
| 127 |
if (email == '') |
| 128 |
{ |
| 129 |
alert("Enter your registered mail id with shiprocket"); |
| 130 |
return false; |
| 131 |
} |
| 132 |
var phone = jQuery('#woocommerce_shiprocket_woocommerce_shipping_phone').val(); |
| 133 |
if (phone == '') |
| 134 |
{ |
| 135 |
alert("Enter your phone"); |
| 136 |
return false; |
| 137 |
} |
| 138 |
var first_name = jQuery('#woocommerce_shiprocket_woocommerce_shipping_first_name').val(); |
| 139 |
if (first_name == '') |
| 140 |
{ |
| 141 |
alert("Enter your first name"); |
| 142 |
return false; |
| 143 |
} |
| 144 |
var last_name = jQuery('#woocommerce_shiprocket_woocommerce_shipping_last_name').val(); |
| 145 |
if (last_name == '') |
| 146 |
{ |
| 147 |
alert("Enter your last name"); |
| 148 |
return false; |
| 149 |
} |
| 150 |
var company_name = jQuery('#woocommerce_shiprocket_woocommerce_shipping_company_name').val(); |
| 151 |
if (company_name == '') |
| 152 |
{ |
| 153 |
alert("Enter your Company name"); |
| 154 |
return false; |
| 155 |
} |
| 156 |
var fallback_rate = jQuery('#woocommerce_shiprocket_woocommerce_shipping_fallback_rate').val(); |
| 157 |
var fallback_rate_title = jQuery('#woocommerce_shiprocket_woocommerce_shipping_shipping_title').val(); |
| 158 |
if (fallback_rate_title && !fallback_rate) |
| 159 |
{ |
| 160 |
alert("Enter fallback rate"); |
| 161 |
return false; |
| 162 |
} |
| 163 |
else if(fallback_rate && !fallback_rate_title) { |
| 164 |
alert("Enter fallback rate title"); |
| 165 |
return false; |
| 166 |
} |
| 167 |
var flat_rate = jQuery('#woocommerce_shiprocket_woocommerce_shipping_flat_rate').val(); |
| 168 |
var flat_title_section = jQuery('#woocommerce_shiprocket_woocommerce_shipping_shipping_title_flat').val(); |
| 169 |
if (flat_title_section && !flat_rate) |
| 170 |
{ |
| 171 |
alert("Enter flat rate"); |
| 172 |
return false; |
| 173 |
} |
| 174 |
else if(flat_rate && !flat_title_section) { |
| 175 |
alert("Enter flat rate title"); |
| 176 |
return false; |
| 177 |
} |
| 178 |
} |
| 179 |
}); |
| 180 |
}); |
| 181 |
</script> |
| 182 |
|
| 183 |
<?php |
| 184 |
} |
| 185 |
|
| 186 |
$logged_in_user_email_id = null; |
| 187 |
if ( is_admin() && ! empty( $_GET['section'] ) && 'shiprocket_woocommerce_shipping' === $_GET['section'] ) { |
| 188 |
$logged_in_user_email_id = Shiprocket_Shipping_Rates_Common::get_current_user_email_id(); |
| 189 |
} |
| 190 |
|
| 191 |
// Settings. |
| 192 |
return array( |
| 193 |
'realtime_enabled' => array( |
| 194 |
'title' => __( 'Realtime Rates', 'shiprocket-woocommerce-shipping-calculator' ), |
| 195 |
'type' => 'checkbox', |
| 196 |
'label' => __( 'Enable', 'shiprocket-woocommerce-shipping-calculator' ), |
| 197 |
'description' => __( 'Enable Realtime courier rates from Shiprocket', 'shiprocket-woocommerce-shipping-calculator' ), |
| 198 |
'desc_tip' => true, |
| 199 |
'default' => 'no', |
| 200 |
), |
| 201 |
'email_id' => array( |
| 202 |
'title' => __( 'Email Id', 'shiprocket-woocommerce-shipping-calculator' ), |
| 203 |
'type' => 'text', |
| 204 |
'default' => $logged_in_user_email_id, |
| 205 |
'description' => __( 'Required for Shiprocket Account.', 'shiprocket-woocommerce-shipping-calculator' ), |
| 206 |
'desc_tip' => true, |
| 207 |
), |
| 208 |
'company_name' => array( |
| 209 |
'title' => __( 'Company Name', 'shiprocket-woocommerce-shipping-calculator' ), |
| 210 |
'type' => 'text', |
| 211 |
'description' => __( 'Required for Shiprocket Account', 'shiprocket-woocommerce-shipping-calculator' ), |
| 212 |
'desc_tip' => true, |
| 213 |
), |
| 214 |
'first_name' => array( |
| 215 |
'title' => __( 'First Name', 'shiprocket-woocommerce-shipping-calculator' ), |
| 216 |
'type' => 'text', |
| 217 |
'description' => __( 'Required for Shiprocket Account', 'shiprocket-woocommerce-shipping-calculator' ), |
| 218 |
'desc_tip' => true, |
| 219 |
), |
| 220 |
'last_name' => array( |
| 221 |
'title' => __( 'Last Name', 'shiprocket-woocommerce-shipping-calculator' ), |
| 222 |
'type' => 'text', |
| 223 |
'description' => __( 'Required for Shiprocket Account', 'shiprocket-woocommerce-shipping-calculator' ), |
| 224 |
'desc_tip' => true, |
| 225 |
), |
| 226 |
'phone' => array( |
| 227 |
'title' => __( 'Phone', 'shiprocket-woocommerce-shipping-calculator' ), |
| 228 |
'type' => 'text', |
| 229 |
'description' => __( 'Required for Shiprocket Account', 'shiprocket-woocommerce-shipping-calculator' ), |
| 230 |
'desc_tip' => true, |
| 231 |
), |
| 232 |
'integration_id' => array( |
| 233 |
'title' => __( 'Integration Id', 'shiprocket-woocommerce-shipping-calculator' ), |
| 234 |
'type' => 'text', |
| 235 |
'description' => __( 'Required for the Plugin to Authenticate Shiprocket Account. If your store is not already integrated with Shiprocket', 'shiprocket-woocommerce-shipping-calculator' ), |
| 236 |
'placeholder' => __( 'It will be autofilled upon clicking the Signup button.', 'shiprocket-woocommerce-shipping-calculator' ), |
| 237 |
'css' => 'pointer-events: none;opacity:0.7;', |
| 238 |
), |
| 239 |
'shipping_title' => array( |
| 240 |
'title' => __( 'Fallback Rate Title', 'shiprocket-woocommerce-shipping-calculator' ), |
| 241 |
'type' => 'text', |
| 242 |
'default' => 'Shipping Rate', |
| 243 |
'description' => __( 'Enter the fallback shipping title that will be applied if none of the Shiprocket couriers are available.', 'shiprocket-woocommerce-shipping-calculator' ), |
| 244 |
'desc_tip' => true, |
| 245 |
), |
| 246 |
'fallback_rate' => array( |
| 247 |
'title' => __( 'Fallback Shipping Rate', 'shiprocket-woocommerce-shipping-calculator' ), |
| 248 |
'type' => 'text', |
| 249 |
'default' => '40', |
| 250 |
'description' => __( 'Enter the fallback shipping charges that will be applied if none of the Shiprocket couriers are available.', 'shiprocket-woocommerce-shipping-calculator' ), |
| 251 |
'desc_tip' => true, |
| 252 |
), |
| 253 |
'shipping_title_flat' => array( |
| 254 |
'title' => __( 'Flat Rate Title', 'shiprocket-woocommerce-shipping-calculator' ), |
| 255 |
'type' => 'text', |
| 256 |
'default' => 'Flat Rate', |
| 257 |
'description' => __( 'This name will be displayed when the real-time rates setting is disabled for your account.', 'shiprocket-woocommerce-shipping-calculator' ), |
| 258 |
'desc_tip' => true, |
| 259 |
), |
| 260 |
'flat_rate' => array( |
| 261 |
'title' => __( 'Flat Shipping Rate', 'shiprocket-woocommerce-shipping-calculator' ), |
| 262 |
'type' => 'text', |
| 263 |
'default' => '40', |
| 264 |
'description' => __( 'Enter the flat shipping rates that should be applied to each order. When the real-time rates are disabled, flat shipping rates will be displayed.', 'shiprocket-woocommerce-shipping-calculator' ), |
| 265 |
'desc_tip' => true, |
| 266 |
), |
| 267 |
'zone_wise_enabled' => array( |
| 268 |
'title' => __( 'Zone Wise Shipping', 'shiprocket-woocommerce-shipping-calculator' ), |
| 269 |
'type' => 'checkbox', |
| 270 |
'label' => __( 'Enable', 'shiprocket-woocommerce-shipping-calculator' ), |
| 271 |
'description' => __( 'Add Shiprocket App Configuration to your shipping zones to support shiprocket shipping once this option is enabled.<br/><b>Note</b>: Create a Default Zone and add <b>Shiprocket App Configuration</b> shipping method to support Shiprocket Shipping by <b>default</b>', 'shiprocket-woocommerce-shipping-calculator' ), |
| 272 |
'default' => 'no', |
| 273 |
), |
| 274 |
); |
| 275 |
|