Skip to content

Instantly share code, notes, and snippets.

@maxrice
Last active June 23, 2022 18:37
Show Gist options
  • Save maxrice/289b8730a363d46fcb7d048f3d9e2e26 to your computer and use it in GitHub Desktop.
Save maxrice/289b8730a363d46fcb7d048f3d9e2e26 to your computer and use it in GitHub Desktop.
Remove the leading "woocommerce_" from the Woo REST API payment_method attribute
<?php
add_filter( 'woocommerce_rest_prepare_shop_order_object', function( $response ) {
// strip leading woocommerce_ from payment method
if ( ! empty( $response->data['payment_method'] ) ) {
$response->data['payment_method'] = str_replace( 'woocommerce_first_data_', '', $response->data['payment_method'] );
}
return $response;
}, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment