-
-
Save bekarice/38beb1f6619ef191b2abef3806d5bda6 to your computer and use it in GitHub Desktop.
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 // only copy if needed | |
/** | |
* Adds a "Request Refund" action to the account for paid orders | |
* REQUIRES WooCommerce 2.5+ | |
* | |
* @param array $actions the account actions for the order | |
* @param \WC_Order $order | |
* @return array updated actions | |
*/ | |
function sww_add_account_refund_order_action( $actions, $order ) { | |
if ( $order->is_paid() ) { | |
$actions['refund_request'] = array( | |
'url' => sww_get_order_refund_request_url( $order ), | |
'name' => __( 'Request Refund', 'my-textdomain' ), | |
); | |
} | |
return $actions; | |
} | |
add_filter( 'woocommerce_my_account_my_orders_actions', 'sww_add_account_refund_order_action', 10, 2 ); | |
/** | |
* Add a "Request Refund" link to order emails if the order is paid for | |
* REQUIRES WooCommerce 2.5+ | |
* | |
* @param \WC_Order $order | |
*/ | |
function sww_add_refund_request_email_link( $order ) { | |
if ( $order->is_paid() ) { | |
echo '<br /><a class="link" href="' . esc_url( sww_get_order_refund_request_url( $order ) ) . '">Request Refund</a>'; | |
} | |
} | |
add_action( 'woocommerce_email_after_order_table', 'sww_add_refund_request_email_link', 15, 1 ); | |
if ( ! function_exists( 'sww_get_order_refund_request_url' ) ) : | |
/** | |
* Helper function to generate a URL that will add an order number and product list to a refund form | |
* | |
* @param \WC_Order $order | |
* @return string the refund form URL | |
*/ | |
function sww_get_order_refund_request_url( $order ) { | |
// enter the ID for your page that contains the refund request form | |
$page_id = 196; | |
// now we'll build the right refund URL from it | |
$refund_url = trailingslashit( get_page_link( $page_id ) ) . '?order=' . $order->get_order_number(); | |
$products = array(); | |
foreach ( $order->get_items() as $item_id => $item ) { | |
if ( $product = wc_get_product( $item['product_id'] ) ) { | |
$products[] = $product->get_title(); | |
} | |
} | |
if ( ! empty( $products ) ) { | |
$refund_url .= '&products=' . urlencode( implode( ', ', $products ) ); | |
} | |
return $refund_url; | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi where have you added page id