Skip to content

Commit 93d6768

Browse files
issue is fixed now
1 parent 7466c1f commit 93d6768

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

admin/class-track-orders-for-woocommerce-admin.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,4 +2716,50 @@ public function wps_tofw_auto_complete_child_orders( $order_id ) {
27162716
$order->save();
27172717
}
27182718
}
2719+
2720+
/**
2721+
* Update a parent order's line item meta when a child order status changes.
2722+
*
2723+
* @param int $order_id The ID of the order whose status changed.
2724+
* @param string $old_status The previous status of the order.
2725+
* @param string $new_status The new status of the order.
2726+
* @param WC_Order $order The order object.
2727+
*/
2728+
public function wps_update_another_order_on_status_change_hpos( $order_id, $old_status, $new_status, $order ) {
2729+
2730+
// Validate order object.
2731+
if ( ! $order instanceof WC_Order ) {
2732+
return;
2733+
}
2734+
2735+
// Retrieve linked order metadata (HPOS safe).
2736+
$is_child_order_id = $order->get_meta( '_wps_is_child_order' );
2737+
$parent_order_id = $order->get_meta( '_wps_parent_order_id' );
2738+
$cart_line_item_id = $order->get_meta( '_wps_parent_item_id' );
2739+
2740+
// Validate required metadata before proceeding.
2741+
if ( 'yes' !== $is_child_order_id || empty( $parent_order_id ) || empty( $cart_line_item_id ) ) {
2742+
return;
2743+
}
2744+
2745+
// Get parent order object.
2746+
$target_order = wc_get_order( $parent_order_id );
2747+
if ( ! $target_order ) {
2748+
return;
2749+
}
2750+
2751+
// Loop through parent order items and update the matching one.
2752+
foreach ( $target_order->get_items() as $item_id => $item ) {
2753+
if ( (int) $item_id === (int) $cart_line_item_id ) {
2754+
$item->update_meta_data( '_line_item_status', $new_status );
2755+
$item->save();
2756+
$target_order->add_order_note( "Line item #{$item_id} updated to status '{$new_status}' due to child order #{$order_id} status change." );
2757+
break;
2758+
}
2759+
}
2760+
2761+
// Save changes to the parent order.
2762+
$target_order->save();
2763+
}
2764+
27192765
}

includes/class-track-orders-for-woocommerce.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ private function track_orders_for_woocommerce_admin_hooks() {
243243
$this->loader->add_filter( 'manage_edit-shop_order_sortable_columns', $tofw_plugin_admin, 'wps_tofw_shop_order_sortable_columns_callback',10,1);
244244
$this->loader->add_action( 'pre_get_posts', $tofw_plugin_admin, 'wps_tofw_pre_get_posts_cllbck',20,1);
245245
$this->loader->add_action( 'woocommerce_order_status_completed', $tofw_plugin_admin, 'wps_tofw_auto_complete_child_orders',20,1);
246+
$this->loader->add_action( 'woocommerce_order_status_changed', $tofw_plugin_admin, 'wps_update_another_order_on_status_change_hpos', 10, 4 );
246247
}
247248

248249
/**

public/class-track-orders-for-woocommerce-public.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ public function wps_tofw_render_partial_tracking( $order ) {
557557

558558
const wps_tofw_trackingLinks = <?php echo wp_json_encode( $wps_tofw_tracking_numbers ); ?>;
559559
const wps_tofw_productMap = <?php echo wp_json_encode( $wps_tofw_products ); ?>;
560+
const wps_otfw_popup_tracking_page = <?php echo json_encode( get_option( 'wps_tofwp_enable_track_order_popup' ) ); ?>;
560561

561562
wps_tofw_table.querySelectorAll("tbody tr.woocommerce-table__line-item").forEach(function(wps_tofw_row){
562563
const wps_tofw_productName = wps_tofw_row.querySelector(".woocommerce-table__product-name a")?.innerText.trim();
@@ -566,9 +567,15 @@ public function wps_tofw_render_partial_tracking( $order ) {
566567
wps_tofw_td.className = "tracking-link-col";
567568

568569
if (wps_tofw_productId && wps_tofw_trackingLinks[wps_tofw_productId]) {
569-
wps_tofw_td.innerHTML = '<a href="<?php echo esc_url( home_url( '/track-your-order/?' ) ); ?>'
570+
if ( 'on' === wps_otfw_popup_tracking_page ) {
571+
wps_tofw_td.innerHTML = '<a href="<?php echo esc_url( home_url( '/track-your-order/?' ) ); ?>'
572+
+ wps_tofw_trackingLinks[wps_tofw_productId]
573+
+ '&TB_iframe=true&popup_type=track_order" target="_blank" class="wps-tofw-track-btn thickbox">Track Order</a>';
574+
} else {
575+
wps_tofw_td.innerHTML = '<a href="<?php echo esc_url( home_url( '/track-your-order/?' ) ); ?>'
570576
+ wps_tofw_trackingLinks[wps_tofw_productId]
571577
+ '" target="_blank" class="wps-tofw-track-btn">Track Order</a>';
578+
}
572579
} else {
573580
wps_tofw_td.textContent = '-';
574581
}
@@ -658,6 +665,8 @@ public function wps_split_parent_into_children( $parent_order_id ) {
658665
$child->calculate_totals( false );
659666
$child->add_order_note( sprintf( 'Created as child order of #%d for item #%d.', $parent_order_id, $item_id ) );
660667
$child->update_meta_data( '_wps_is_child_order', 'yes' );
668+
$child->update_meta_data( '_wps_parent_item_id', $item_id );
669+
$child->update_meta_data( '_wps_parent_order_id', $parent_order_id );
661670
$child->save();
662671

663672
$child_ids[ $item->get_product_id() ] = $child->get_id();

0 commit comments

Comments
 (0)