Changeset 3338927
- Timestamp:
- 08/04/2025 11:45:45 AM (8 months ago)
- Location:
- pikkolo/trunk
- Files:
-
- 3 edited
-
inc/functions.php (modified) (4 diffs)
-
pikkolo.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pikkolo/trunk/inc/functions.php
r3031882 r3338927 1 1 <?php 2 /* 3 ** Helper Functions 4 */ 5 2 /** 3 * Helper Functions 4 * 5 * @package PikkoloWooUtils 6 */ 6 7 7 8 /* … … 11 12 exit; } 12 13 13 /**14 * Try to get the delivery date from the billing fields.15 *16 * @param array $billing_fields The billing fields array.17 * @return string18 */19 function pikkolois_get_delivery_date( array $billing_fields ): string {20 $delivery_date = $billing_fields['billing_delivery_date'];21 $d_m_y = DateTime::createFromFormat( 'd#m#Y', $delivery_date );22 $y_m_d = DateTime::createFromFormat( 'Y#m#d', $delivery_date );23 if ( $d_m_y ) {24 return $d_m_y->format( 'Y-m-d' );25 }26 if ( $y_m_d ) {27 return $y_m_d->format( 'Y-m-d' );28 }29 return '';30 }31 14 32 15 /** … … 80 63 81 64 $wc_product = $product->get_product(); 82 65 83 66 $weight = $wc_product ? $wc_product->get_weight() : 0; 84 67 $dimensions = $wc_product ? $wc_product->get_dimensions() : array(); … … 139 122 ); 140 123 } 124 125 126 127 /** 128 * Prepares the post fields for sending to the Pikkoló API. 129 * 130 * @param Pikkolo_Shipping_Method $pikkolo The Pikkoló shipping method instance. 131 * @param WC_Order $order The WooCommerce order object. 132 * @param array $product_data The product data array containing items, refrigerated count, frozen count, and age restriction value. 133 * @param WC_Logger $log The WooCommerce logger instance for debugging. 134 */ 135 function pikkolo_prepare_post_fields( $pikkolo, $order, $product_data, $log ) { 136 // Get cookies set in pikkolo.js. 137 $station_id = isset( $_COOKIE['pikkolo_station_id'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['pikkolo_station_id'] ) ) : ''; 138 139 // Get delivery date from order meta data if it exists. 140 $delivery_date_from_meta = pikkolois_get_delivery_date_from_order_meta_data( $order ); 141 142 // Get delivery date from checkout page if it exists. 143 $delivery_date_from_checkout = pikkolois_get_delivery_date( WC()->checkout()->get_posted_data() ); 144 145 if ( 'yes' === ( $pikkolo->debug ) ) { 146 $log->add( 'pikkolois', "Delivery date from meta {$delivery_date_from_meta}" ); 147 $log->add( 'pikkolois', "Delivery date from checkout $delivery_date_from_checkout" ); 148 } 149 150 $vendor_order_id = strval( $order->get_id() ); 151 $customer_phone = strval( $order->get_billing_phone() ); 152 $customer_email = strval( $order->get_billing_email() ); 153 $customer_name = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(); 154 155 $ret = array( 156 'vendorOrderId' => $vendor_order_id, 157 'stationId' => $station_id, 158 'customerPhone' => $customer_phone, 159 'customerEmail' => $customer_email, 160 'customerName' => $customer_name, 161 'isSubscription' => false, 162 'pickupAuthenticationAge' => intval( $product_data['age_restriction_value'] ) > 0 ? intval( $product_data['age_restriction_value'] ) : 0, 163 'nrOfRefrigeratedItems' => $product_data['refrigerated_count'], 164 'nrOfFreezerItems' => $product_data['frozen_count'], 165 'items' => $product_data['items'], 166 ); 167 if ( $delivery_date_from_meta ) { 168 $ret['deliveryTimeId'] = $station_id . ':' . $delivery_date_from_meta; 169 } 170 if ( $delivery_date_from_checkout ) { 171 $ret['deliveryTimeId'] = $station_id . ':' . $delivery_date_from_checkout; 172 } 173 174 return $ret; 175 } -
pikkolo/trunk/pikkolo.php
r3191538 r3338927 4 4 Plugin URI: https://pikkolo.is/ 5 5 Description: Shipping method 6 Version: 1.0. 46 Version: 1.0.6 7 7 Author: Pikkoló ehf. 8 8 Text Domain: pikkolois … … 10 10 */ 11 11 if ( ! defined( 'ABSPATH' ) ) { 12 exit; // Exit if accessed directly 12 exit; // Exit if accessed directly. 13 13 } 14 14 … … 16 16 require_once __DIR__ . '/inc/functions.php'; 17 17 } 18 19 if ( file_exists( __DIR__ . '/inc/dates.php' ) ) { 20 require_once __DIR__ . '/inc/dates.php'; 21 } 22 18 23 /** 19 24 * Check if WooCommerce is active … … 681 686 682 687 /** 683 * Books a Pikk óloslot when a order is processed.688 * Books a Pikkoló slot when a order is processed. 684 689 * 685 690 * @param int $order_id The ID of the processed order. … … 700 705 $products_data = pikkolois_get_products_data( $order ); 701 706 702 $post_fields = pikkolo_prepare_post_fields( $ order, $products_data);707 $post_fields = pikkolo_prepare_post_fields( $pikkolo, $order, $products_data, $log ); 703 708 704 709 $result = pikkolo_send_order_to_api( $pikkolo, $post_fields, $log ); … … 713 718 } 714 719 add_action( 'woocommerce_checkout_order_processed', 'pikkolo_process_order', 10, 1 ); 715 716 function pikkolo_prepare_post_fields( $order, $product_data ) {717 // Get cookies set in pikkolo.js718 $station_id = sanitize_text_field( $_COOKIE['pikkolo_station_id'] );719 // $delivery_time_id = sanitize_text_field($_COOKIE['pikkolo_delivery_time_id']);720 721 // Get delivery date from checkout page if it exists.722 $delivery_date_from_checkout = pikkolois_get_delivery_date( WC()->checkout()->get_posted_data() );723 724 $vendor_order_id = strval( $order->get_id() );725 $customer_phone = strval( $order->get_billing_phone() );726 $customer_email = strval( $order->get_billing_email() );727 $customer_name = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();728 729 $ret = array(730 'vendorOrderId' => $vendor_order_id,731 'stationId' => $station_id,732 'customerPhone' => $customer_phone,733 'customerEmail' => $customer_email,734 'customerName' => $customer_name,735 'isSubscription' => false,736 'pickupAuthenticationAge' => intval( $product_data['age_restriction_value'] ) > 0 ? intval( $product_data['age_restriction_value'] ) : 0,737 'nrOfRefrigeratedItems' => $product_data['refrigerated_count'],738 'nrOfFreezerItems' => $product_data['frozen_count'],739 'items' => $product_data['items'],740 );741 if ( $delivery_date_from_checkout ) {742 $ret['deliveryTimeId'] = $station_id . ':' . $delivery_date_from_checkout;743 }744 return $ret;745 }746 720 747 721 function pikkolo_send_order_to_api( $pikkolo, $post_fields, $log ) { -
pikkolo/trunk/readme.txt
r3191538 r3338927 8 8 WC requires at least: 3.8.1 9 9 WC tested up to: 9.4.1 10 Stable tag: 1.0. 510 Stable tag: 1.0.6 11 11 12 12 == Installation == … … 34 34 == Changelog == 35 35 36 = 1.0.6 = 37 * Enable detection of the delivery date from the order meta data 38 36 39 = 1.0.5 = 37 40 * Documentation updates
Note: See TracChangeset
for help on using the changeset viewer.