get_meta( aisp_order_tracking_notification_Helpers::META_CARRIER ); $tracking = $order->get_meta( aisp_order_tracking_notification_Helpers::META_TRACKING ); if ( empty( $carrier ) || empty( $tracking ) ) { return $actions; } $url = aisp_order_tracking_notification_Helpers::aisp_order_tracking_notification_get_tracking_url( $carrier, $tracking ); if ( empty( $url ) ) { return $actions; } $actions['track_shipment'] = [ 'url' => esc_url( $url ), 'name' => __( 'Track Shipment', 'aisp-order-tracking-notification' ), 'type' => 'view', ]; return $actions; } // Register label-created as a valid WooCommerce order status add_action( 'init', function() { register_post_status( 'wc-label-created', [ 'label' => _x( 'Label Created', 'Order status', 'aisp-order-tracking-notification' ), 'public' => false, 'exclude_from_search' => false, 'show_in_admin_all_list' => false, 'show_in_admin_status_list' => false, // translators: %s: number of orders with Label Created status. 'label_count' => _n_noop( 'Label Created (%s)', 'Label Created (%s)', 'aisp-order-tracking-notification' ), ]); }); // When an order reaches label-created, automatically transition to completed add_action( 'woocommerce_order_status_changed', function( $order_id, $old_status, $new_status ) { if ( 'label-created' === $new_status ) { $order = wc_get_order( $order_id ); if ( $order ) { $order->update_status( 'completed', 'Label created — order automatically marked as completed.' ); } } if ( 'cancelled' === $new_status && 'completed' === $old_status ) { $order = wc_get_order( $order_id ); if ( $order ) { $order->update_status( 'processing', 'Label cancelled — order automatically returned to processing.' ); } } }, 10, 3 ); add_filter( 'wc_order_statuses', function( $statuses ) { $statuses['wc-label-created'] = _x( 'Label Created', 'Order status', 'aisp-order-tracking-notification' ); return $statuses; });