New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support gift cards in admin order refunds template #31414
Conversation
@woocommerce/proton see pdqkbG-6O-p2#comment-173 |
@@ -282,7 +282,7 @@ | |||
<?php else : ?> | |||
<span class="description"><?php echo wc_help_tip( __( 'To edit this order change the status back to "Pending payment"', 'woocommerce' ) ); ?> <?php esc_html_e( 'This order is no longer editable.', 'woocommerce' ); ?></span> | |||
<?php endif; ?> | |||
<?php if ( 0 < $order->get_total() - $order->get_total_refunded() || 0 < absint( $order->get_item_count() - $order->get_item_count_refunded() ) ) : ?> | |||
<?php if ( (bool) apply_filters( 'woocommerce_admin_order_should_render_refunds', 0 < $order->get_total() - $order->get_total_refunded() || 0 < absint( $order->get_item_count() - $order->get_item_count_refunded() ), $order->get_id(), $order ) ) : ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where possible we should avoid placing filter hooks inside templates and we should also document any new hooks we add.
I realize the duplication of the logic predates your change, and you were just wrapping it in a filter, but this is actually a pretty nice opportunity to clean it up. We could for example place the hook inside WC_Meta_Box_Order_Items::output()
(adding a docblock to explain what it does) and then pass the result in here as a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review, @barryhughes! Sounds reasonable!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this: seems reasonable but a few small changes are needed.
Tests are failing.
Adding a filter into the Instead of writing the same filter in multiple places, we could:
Moreover, I think introducing a new variable inside the Another way could be to introduce a global helper function, e.g., In my opinion, and because the template in question is widely used, I would opt for leaving the filter inline. Although, I understand your point that this filter would be used twice in the same template, which is not ideal. Thoughts? |
You're right, it doesn't seem viable in this case and there isn't a particularly clean way to tidy this up without a larger body of work.
It still seems a shame to repeat it unnecessarily by inlining it. Given that all of the other data available to the template remains the same, do you see difficulties if we do something along these lines (ie, place the filter once at the top of the template): <?php
/**
* Order items HTML for meta box.
*
* @package WooCommerce\Admin
*/
/**
* Docblock for the new filter.
*/
$render_refunds = (bool) apply_filters( 'woocommerce_admin_order_should_render_refunds', 0 < $order->get_total() - $order->get_total_refunded() || 0 < absint( $order->get_item_count() - $order->get_item_count_refunded() ), $order->get_id(), $order );
?>
<!-- Other template code -->
<?php if ( $render_refunds ) : ?>
<!-- Refund HTML -->
<?php endif; ?>
<!-- Other template code --> |
I feel the same way!
No. Placing the filter once at the top of the template seems like a good idea at this point! |
Excellent, thanks. I tweaked the docblock a little (I believe this will actually ship in 6.4) and once tests pass I'll go ahead and merge. Thanks for the contribution :-) |
Hi @barryhughes, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
Thanks, @barryhughes! 🙇 |
Closes #31413
Specification
Please check the issue description for additional details.
Changelog