only show refund via button when gateway supports refunds #3164

This commit is contained in:
claudiosmweb 2014-07-22 12:13:35 -03:00
parent d823428745
commit 954a5ddc23
2 changed files with 31 additions and 1 deletions

View File

@ -16,6 +16,9 @@ if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) {
}
}
// Get the payment gateway
$payment_gateway = wc_get_payment_gateway_by_order( $order );
?>
<div class="woocommerce_order_items_wrapper wc-order-items-editable">
<table cellpadding="0" cellspacing="0" class="woocommerce_order_items">
@ -60,7 +63,7 @@ if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) {
foreach ( $order_items as $item_id => $item ) {
$_product = $order->get_product_from_item( $item );
$item_meta = $order->get_item_meta( $item_id );
include( 'html-order-item.php' );
do_action( 'woocommerce_order_item_' . $item['type'] . '_html', $item_id, $item );
@ -201,7 +204,9 @@ if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) {
</table>
<div class="clear"></div>
<div class="refund-actions">
<?php if ( false !== $payment_gateway && $payment_gateway->supports( 'refunds' ) ) : ?>
<button type="button" class="button button-primary do-api-refund"><?php printf( _x( 'Refund %s via %s', 'Refund $amount', 'woocommerce' ), '<span class="wc-order-refund-amount">' . wc_price( 0 ) . '</span>', $order->payment_method_title ); ?></button>
<?php endif; ?>
<button type="button" class="button button-primary do-manual-refund"><?php _e( 'Refund manually', 'woocommerce' ); ?></button>
<button type="button" class="button cancel-action"><?php _e( 'Cancel', 'woocommerce' ); ?></button>
<div class="clear"></div>

View File

@ -585,3 +585,28 @@ function wc_get_tax_class_by_tax_id( $tax_id ) {
return wc_clean( $tax_class );
}
/**
* Get payment gateway class by order data.
*
* @since 2.2
* @param int|WC_Order $order
* @return WC_Payment_Gateway|bool
*/
function wc_get_payment_gateway_by_order( $order ) {
if ( WC()->payment_gateways() ) {
$payment_gateways = WC()->payment_gateways->payment_gateways();
} else {
$payment_gateways = array();
}
if ( is_object( $order ) ) {
$payment_method = $order->payment_method;
} else {
$order_id = absint( $order );
$order = new WC_Order( $order_id );
$payment_method = $order->payment_method;
}
return isset( $payment_gateways[ $order->payment_method ] ) ? $payment_gateways[ $order->payment_method ] : false;
}