Changeset 3166489
- Timestamp:
- 10/10/2024 11:09:00 AM (17 months ago)
- Location:
- shipbubble
- Files:
-
- 49 added
- 6 edited
-
tags/2.6 (added)
-
tags/2.6/admin (added)
-
tags/2.6/admin/css (added)
-
tags/2.6/admin/css/styles-wc.css (added)
-
tags/2.6/admin/index.php (added)
-
tags/2.6/admin/js (added)
-
tags/2.6/admin/js/ajax-create-shipment.js (added)
-
tags/2.6/admin/js/ajax-validate-address.js (added)
-
tags/2.6/admin/js/ajax-validate-auth.js (added)
-
tags/2.6/admin/woocommerce (added)
-
tags/2.6/admin/woocommerce/async-create-shipment.php (added)
-
tags/2.6/admin/woocommerce/async-validate-address.php (added)
-
tags/2.6/admin/woocommerce/enqueue-styles.php (added)
-
tags/2.6/admin/woocommerce/orders.php (added)
-
tags/2.6/admin/woocommerce/shipping-settings.php (added)
-
tags/2.6/admin/wordpress (added)
-
tags/2.6/admin/wordpress/async-validate-auth.php (added)
-
tags/2.6/admin/wordpress/index.php (added)
-
tags/2.6/admin/wordpress/settings-callback.php (added)
-
tags/2.6/admin/wordpress/settings-field-validation.php (added)
-
tags/2.6/admin/wordpress/settings-menu.php (added)
-
tags/2.6/admin/wordpress/settings-page.php (added)
-
tags/2.6/admin/wordpress/settings-register.php (added)
-
tags/2.6/includes (added)
-
tags/2.6/includes/constants.php (added)
-
tags/2.6/includes/core-methods.php (added)
-
tags/2.6/includes/endpoints.php (added)
-
tags/2.6/includes/index.php (added)
-
tags/2.6/index.php (added)
-
tags/2.6/languages (added)
-
tags/2.6/languages/index.php (added)
-
tags/2.6/license.txt (added)
-
tags/2.6/public (added)
-
tags/2.6/public/async-checkout-couriers.php (added)
-
tags/2.6/public/css (added)
-
tags/2.6/public/css/styles-wc.css (added)
-
tags/2.6/public/images (added)
-
tags/2.6/public/images/logo.svg (added)
-
tags/2.6/public/js (added)
-
tags/2.6/public/js/blockui (added)
-
tags/2.6/public/js/blockui/jquery.blockUI.js (added)
-
tags/2.6/public/js/couriers-on-checkout.js (added)
-
tags/2.6/public/js/sweetalert2.min.js (added)
-
tags/2.6/public/woocommerce (added)
-
tags/2.6/public/woocommerce/checkout.php (added)
-
tags/2.6/public/woocommerce/enqueue-styles.php (added)
-
tags/2.6/readme.txt (added)
-
tags/2.6/shipbubble.php (added)
-
tags/2.6/uninstall.php (added)
-
trunk/admin/woocommerce/async-create-shipment.php (modified) (1 diff)
-
trunk/admin/woocommerce/orders.php (modified) (6 diffs)
-
trunk/includes/core-methods.php (modified) (2 diffs)
-
trunk/public/js/couriers-on-checkout.js (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/shipbubble.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shipbubble/trunk/admin/woocommerce/async-create-shipment.php
r3101414 r3166489 40 40 41 41 // get shipment details 42 $shipmentPayload = unserialize( get_post_meta($orderId, 'shipbubble_shipment_details')[0]);42 $shipmentPayload = unserialize(shipbubble_get_order_meta($orderId, 'shipbubble_shipment_details')); 43 43 44 44 // set time meta to initiate the request 45 45 $shipmentPayload['admin_initiate_shipment_time'] = date('Y-m-d H:i:s'); 46 update_post_meta($orderId, 'shipbubble_shipment_details', serialize($shipmentPayload)); 46 shipbubble_update_order_meta($orderId, 'shipbubble_shipment_details', serialize($shipmentPayload)); 47 48 if (!isset($shipmentPayload) || empty($shipmentPayload['request_token']) || empty($shipmentPayload['courier_id']) || empty($shipmentPayload['service_code'])) { 49 $checkoutPayload = unserialize(shipbubble_get_order_meta($orderId, 'sb_shipment_meta')); 50 51 // TODO: check token expiry 52 if (empty($shipmentPayload['request_token'])) { 53 $shipmentPayload['request_token'] = $checkoutPayload['shipment_payload']['request_token'] ?? ''; 54 } 55 56 if (empty($shipmentPayload['courier_id'])) { 57 $shipmentPayload['courier_id'] = $checkoutPayload['shipment_payload']['courier_id'] ?? ''; 58 } 59 if (empty($shipmentPayload['service_code'])) { 60 $shipmentPayload['service_code'] = $checkoutPayload['shipment_payload']['service_code'] ?? ''; 61 } 62 63 $shipmentPayload['swap_occurred'] = true; 64 65 // initiate request 66 } 67 $response = shipbubble_create_shipment($shipmentPayload); 47 68 48 69 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]); 54 55 // TODO: check token expiry 56 if (empty($shipmentPayload['request_token'])) { 57 $shipmentPayload['request_token'] = $checkoutPayload['shipment_payload']['request_token'] ?? ''; 58 } 59 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 } 66 67 $shipmentPayload['swap_occurred'] = true; 68 69 // initiate request 70 $response = shipbubble_create_shipment($shipmentPayload); 71 } 72 73 74 if (isset($response->response_code) && $response->response_code == SHIPBUBBLE_RESPONSE_IS_OK) 75 { 70 if (isset($response->response_code) && $response->response_code == SHIPBUBBLE_RESPONSE_IS_OK) { 76 71 // set shipbubble order id 77 update_post_meta( $orderId, 'shipbubble_order_id', $response->data->order_id );72 shipbubble_update_order_meta( $orderId, 'shipbubble_order_id', $response->data->order_id ); 78 73 79 74 // set time meta 80 75 $shipmentPayload['admin_create_shipment_time'] = date('Y-m-d H:i:s'); 81 update_post_meta($orderId, 'shipbubble_shipment_details', serialize($shipmentPayload));76 shipbubble_update_order_meta($orderId, 'shipbubble_shipment_details', serialize($shipmentPayload)); 82 77 83 78 // set shipping status 84 update_post_meta( $orderId, 'shipbubble_tracking_status', 'pending' );79 shipbubble_update_order_meta( $orderId, 'shipbubble_tracking_status', 'pending' ); 85 80 } 86 81 -
shipbubble/trunk/admin/woocommerce/orders.php
r3137294 r3166489 17 17 18 18 // Get Shipbubble Order ID 19 $shipbubbleOrderId = get_post_meta($order_id, 'shipbubble_order_id', true);20 21 $serializedShipment = get_post_meta($order_id, 'shipbubble_shipment_details')[0];19 $shipbubbleOrderId = shipbubble_get_order_meta($order_id, 'shipbubble_order_id', true); 20 21 $serializedShipment = shipbubble_get_order_meta($order_id, 'shipbubble_shipment_details'); 22 22 $style = "background-color: #000; color: #FFF; padding: 4px 16px; border: 1px solid #000; border-radius: 3px; cursor: not-allowed;"; 23 23 … … 59 59 $shippingPhone = $order_data['billing']['phone']; 60 60 $orderAddress = sb_create_address($shippingData['address_1'], $shippingData['city'], $shippingData['state'], $shippingData['country']); 61 $orderPhone = get_post_meta($order_id, 'shipbubble_delivery_phone', true);61 $orderPhone = shipbubble_get_order_meta($order_id, 'shipbubble_delivery_phone', true); 62 62 63 63 if (empty($orderPhone)) { 64 64 $orderPhone = $shippingPhone; 65 update_post_meta($order_id, 'shipbubble_delivery_phone', $orderPhone);65 shipbubble_update_order_meta($order_id, 'shipbubble_delivery_phone', $orderPhone); 66 66 } 67 67 68 68 // Get Delivery Address 69 $shipbubbleDeliveryAddress = get_post_meta($order_id, 'shipbubble_delivery_address', true);69 $shipbubbleDeliveryAddress = shipbubble_get_order_meta($order_id, 'shipbubble_delivery_address', true); 70 70 71 71 // serialize shipment … … 140 140 if ($order->has_shipping_method(SHIPBUBBLE_ID)) { 141 141 // Check Shipping Status 142 $status = get_post_meta($post->ID, 'shipbubble_tracking_status', true);142 $status = shipbubble_get_order_meta($post->ID, 'shipbubble_tracking_status', true); 143 143 if (!empty($status)) { 144 144 echo shipbubble_shipment_status_label($status); … … 213 213 global $post; 214 214 215 $shipbubbleOrderId = get_post_meta($post->ID, 'shipbubble_order_id', true) ?? '';215 $shipbubbleOrderId = shipbubble_get_order_meta($post->ID, 'shipbubble_order_id', true) ?? ''; 216 216 217 217 $response = null; … … 232 232 233 233 // set shipping status 234 update_post_meta($post->ID, 'shipbubble_tracking_status', strtolower($latestPackageStatus->status));234 shipbubble_update_order_meta($post->ID, 'shipbubble_tracking_status', strtolower($latestPackageStatus->status)); 235 235 236 236 ?> … … 274 274 } 275 275 276 if (!count(get_post_meta($order->get_id(), 'shipbubble_shipment_details'))) { 277 return; 278 } 279 280 $shipbubbleOrderId = get_post_meta($order->get_id(), 'shipbubble_order_id', true); 276 $shipment_details = maybe_unserialize(shipbubble_get_order_meta($order->get_id(), 'shipbubble_shipment_details')); 277 278 if (empty($shipment_details) || !count($shipment_details)) { 279 return; 280 } 281 282 $shipbubbleOrderId = shipbubble_get_order_meta($order->get_id(), 'shipbubble_order_id', true); 281 283 if (strlen($shipbubbleOrderId) < 1) { 282 284 $response = shipbubble_get_wallet_balance(shipbubble_get_token()); -
shipbubble/trunk/includes/core-methods.php
r3137294 r3166489 1 1 <?php // Core Methods 2 2 use \Yay_Currency\Helpers\YayCurrencyHelper; 3 use Automattic\WooCommerce\Utilities\OrderUtil; 3 4 4 5 function shipbubble_get_token(): string … … 503 504 } 504 505 } 506 507 /** 508 * Update order meta data for a given order. 509 * 510 * This function retrieves an order by its ID, updates its meta data, and saves the order. 511 * 512 * @param int $order_id The ID of the order to update. 513 * @param string $meta_key The meta key to update or add. 514 * @param mixed $meta_value The meta value to set for the given meta key. 515 * 516 * @return bool Returns true if the order was updated successfully, false otherwise. 517 */ 518 function shipbubble_update_order_meta($order_id, $meta_key, $meta_value) { 519 $order = wc_get_order($order_id); 520 521 if (!$order) return false; 522 523 $order->update_meta_data($meta_key, $meta_value); 524 $order->save(); 525 526 return true; 527 } 528 529 /** 530 * Retrieve order meta data for a given order. 531 * 532 * This function fetches meta data for an order using WooCommerce's order meta system. 533 * If the order is not migrated, it falls back to using the post meta system. 534 * 535 * @param int $order_id The ID of the order to retrieve meta data from. 536 * @param string $meta_key The meta key to retrieve the value for. 537 * 538 * @return mixed The meta value if found, or an empty string if the order does not exist or the meta data is not available. 539 */ 540 function shipbubble_get_order_meta($order_id, $meta_key) { 541 $order = wc_get_order($order_id); 542 543 if (!$order) return ''; 544 if (shipbubble_is_order_migrated($order)) { 545 $metadata = $order->get_meta($meta_key); 546 } else { 547 $metadata = get_post_meta($order_id, $meta_key, true); 548 } 549 550 return $metadata; 551 } 552 553 /** 554 * Check if a WooCommerce order has been migrated based on the database update time. 555 * 556 * This function compares the order's creation date with the `shipbubble_db_update_time` option 557 * to determine if the order was created after the migration date, thus marking it as migrated. 558 * 559 * @param WC_Order $order The WooCommerce order object to check. 560 * 561 * @return bool Returns true if the order is considered migrated, false otherwise. 562 */ 563 function shipbubble_is_order_migrated($order) { 564 $updated_time = get_option('shipbubble_db_update_time'); 565 566 if (!$updated_time) return false; 567 568 // Get the order creation date (WooCommerce stores this in the order object) 569 $order_date = $order->get_date_created(); // Returns a DateTime object 570 571 // Convert the order date to a timestamp for comparison 572 $order_timestamp = $order_date ? $order_date->getTimestamp() : 0; 573 574 // Compare the order timestamp with the updated time 575 if ($order_timestamp >= $updated_time) { 576 return true; // Order is considered migrated 577 } else { 578 return false; // Order is not migrated 579 } 580 } -
shipbubble/trunk/public/js/couriers-on-checkout.js
r3149400 r3166489 1544 1544 } 1545 1545 } 1546 }); 1546 1547 $("form.woocommerce-checkout").on('checkout_place_order', function(e) { 1548 // Check if the radio button with value 'shipbubble_shipping_services' is checked 1549 var isShipbubbleChecked = $('input[name="shipping_method[0]"][value="shipbubble_shipping_services"]').is(':checked'); 1550 1551 if (isShipbubbleChecked) { 1552 // Skip the confirmation prompt if 'shipbubble_shipping_services' is checked 1553 return true; 1554 } else { 1555 // Show the confirmation prompt if any other shipping method is selected 1556 if (!confirm("You've chosen pickup. For home delivery options, click 'Get Delivery Prices'. To proceed with pickup, click 'OK'.")) { 1557 console.log("Submission Stopped"); 1558 return false; 1559 } 1560 } 1561 }); 1562 1563 }); 1547 1564 1548 1565 })(jQuery); -
shipbubble/trunk/readme.txt
r3156194 r3166489 5 5 Requires at least: 4.0 6 6 Tested up to: 6.5 7 Stable tag: 2. 5.27 Stable tag: 2.6 8 8 Requires PHP: 5.6 9 9 License: GPLv3 or later … … 70 70 71 71 == Changelog == 72 = 2.6 = 73 * HPOS support and checkout assist for pickup orders. 74 72 75 = 2.5.2 = 73 76 * Currncy plugin checkout support fix. -
shipbubble/trunk/shipbubble.php
r3156194 r3166489 9 9 * Requires at least: 4.0 10 10 * Tested up to: 6.5 11 * Version: 2. 5.211 * Version: 2.6 12 12 * Requires PHP: 5.6 13 13 * Text Domain: shipbubble … … 139 139 } 140 140 141 $update_time = get_option('shipbubble_db_update_time'); 142 if (empty($update_time)) { 143 add_option('shipbubble_db_update_time', time()); 144 } 145 141 146 } 142 147 … … 305 310 306 311 // set shipbubble_shipment_details data to db (for admin create) 307 update_post_meta($order_id, 'shipbubble_shipment_details', serialize($shipbubbleShipmentDetails));312 shipbubble_update_order_meta($order_id, 'shipbubble_shipment_details', serialize($shipbubbleShipmentDetails)); 308 313 309 314 // set payload to create shipbubble shipment (for checkout create) 310 update_post_meta($order_id, 'sb_shipment_meta', serialize($shipmentMeta));315 shipbubble_update_order_meta($order_id, 'sb_shipment_meta', serialize($shipmentMeta)); 311 316 312 317 // setting the delivery address 313 update_post_meta($order_id, 'shipbubble_delivery_address', $address);318 shipbubble_update_order_meta($order_id, 'shipbubble_delivery_address', $address); 314 319 315 320 // setting the phone number 316 update_post_meta($order_id, 'shipbubble_delivery_phone', $phone);321 shipbubble_update_order_meta($order_id, 'shipbubble_delivery_phone', $phone); 317 322 } 318 323 } … … 334 339 335 340 add_action('woocommerce_thankyou', 'shipbubble_create_shipment_after_order_created', 10, 1); 341 add_action('woocommerce_order_status_pending_to_processing', 'shipbubble_create_shipment_after_order_created', 10, 1); 336 342 function shipbubble_create_shipment_after_order_created($order_id) 337 343 { … … 339 345 return; 340 346 341 if (! get_post_meta($order_id, 'shipbubble_shipment_details', true))347 if (!shipbubble_get_order_meta($order_id, 'shipbubble_shipment_details', true)) 342 348 return; 343 349 344 350 // Allow code execution only once 345 if (! get_post_meta($order_id, '_thankyou_action_done', true)) {351 if (!shipbubble_get_order_meta($order_id, '_thankyou_action_done', true)) { 346 352 347 353 // Get an instance of the WC_Order object 348 354 $order = wc_get_order($order_id); 349 355 350 $shipmentMeta = unserialize( get_post_meta($order_id, 'sb_shipment_meta')[0]);356 $shipmentMeta = unserialize(shipbubble_get_order_meta($order_id, 'sb_shipment_meta')); 351 357 352 358 if (count($shipmentMeta)) { … … 357 363 if (isset($response->response_code) && $response->response_code == SHIPBUBBLE_RESPONSE_IS_OK) { 358 364 // set shipbubble order id 359 update_post_meta($order_id, 'shipbubble_order_id', $response->data->order_id);365 shipbubble_update_order_meta($order_id, 'shipbubble_order_id', $response->data->order_id); 360 366 361 367 // set shipping status 362 update_post_meta($order_id, 'shipbubble_tracking_status', 'pending');363 364 $shipmentDetailsArray = unserialize( get_post_meta($order_id, 'shipbubble_shipment_details')[0]);368 shipbubble_update_order_meta($order_id, 'shipbubble_tracking_status', 'pending'); 369 370 $shipmentDetailsArray = unserialize(shipbubble_get_order_meta($order_id, 'shipbubble_shipment_details')); 365 371 366 372 if (count($shipmentDetailsArray)) 367 373 { 368 374 $shipmentDetailsArray['create_shipment_time'] = date('Y-m-d H:i:s'); 369 update_post_meta($order_id, 'shipbubble_shipment_details', serialize($shipmentDetailsArray));375 shipbubble_update_order_meta($order_id, 'shipbubble_shipment_details', serialize($shipmentDetailsArray)); 370 376 } 371 377 } … … 373 379 } else { 374 380 // set empty shipbubble service code 375 update_post_meta($order_id, 'shipbubble_shipment_details', serialize(['service_code' => '']));381 shipbubble_update_order_meta($order_id, 'shipbubble_shipment_details', serialize(['service_code' => ''])); 376 382 377 383 // set empty shipbubble order id 378 update_post_meta($order_id, 'shipbubble_order_id', '');384 shipbubble_update_order_meta($order_id, 'shipbubble_order_id', ''); 379 385 380 386 // set empty shipping status 381 update_post_meta($order_id, 'shipbubble_tracking_status', '');387 shipbubble_update_order_meta($order_id, 'shipbubble_tracking_status', ''); 382 388 } 383 389
Note: See TracChangeset
for help on using the changeset viewer.