<?php
/**
* Plugin Name: POP Cats – Hide Bundle Containers from Legacy REST API
* Description: Removes WooCommerce Product Bundles container line items from
* Legacy REST API (v3) order responses so the AMSCO/ShipHero
* integration imports only the pickable child items.
* The modern REST API (/wp-json/) used by Shippo, Zoho, etc.
* is completely untouched — this hook only exists in the
* Legacy API request lifecycle.
* Author: POP Cats
* Version: 1.0.0
*/
defined( 'ABSPATH' ) || exit;
add_filter( 'woocommerce_api_order_response', function ( $order_data, $order ) {
// Bail early if Product Bundles isn't active, the response has no
// line items, or we didn't receive a proper order object.
if (
! function_exists( 'wc_pb_is_bundle_container_order_item' )
|| empty( $order_data['line_items'] )
|| ! $order instanceof WC_Order
) {
return $order_data;
}
$order_items = $order->get_items();
$order_data['line_items'] = array_values( array_filter(
$order_data['line_items'],
function ( $line_item ) use ( $order_items, $order ) {
$item_id = isset( $line_item['id'] ) ? (int) $line_item['id'] : 0;
// Keep anything we can't positively identify.
if ( ! $item_id || ! isset( $order_items[ $item_id ] ) ) {
return true;
}
// Drop bundle container rows (e.g. "Case of 4"); keep everything else.
return ! wc_pb_is_bundle_container_order_item( $order_items[ $item_id ], $order );
}
) );
return $order_data;
}, 10, 2 );