Skip to content

Instantly share code, notes, and snippets.

@bporcelli
Created June 17, 2022 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bporcelli/e435d2684f1238aceb3ac19d4aeedbd0 to your computer and use it in GitHub Desktop.
Save bporcelli/e435d2684f1238aceb3ac19d4aeedbd0 to your computer and use it in GitHub Desktop.
[MarketShip] Remove refunded labels from label list
<?php
/**
* Filters the `shippo_labels` meta value to remove refunded labels.
* Workaround for label purchase limit not being increased after a
* label is refunded.
*
* @param array|string $labels Shippo labels printed for order.
*
* @return array Labels with refunded labels removed.
*/
function ms_filter_shippo_labels( $labels ) {
if ( '' === $labels ) {
// No labels printed for order yet.
return array();
}
return array_filter(
$labels,
function( $label ) {
return $label['status'] !== 'REFUNDED';
}
);
}
add_filter( 'woocommerce_order_get_shippo_labels', 'ms_filter_shippo_labels' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment