Created
June 17, 2022 13:01
-
-
Save bporcelli/e435d2684f1238aceb3ac19d4aeedbd0 to your computer and use it in GitHub Desktop.
[MarketShip] Remove refunded labels from label list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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