Support » Plugin: WooCommerce » Refund Code does not check for Order’s status or Order has been paid

  • Resolved hiheaven01

    (@hiheaven01)


    hi,

    in WC 3.6.5:

    From admin, do search & add item and save order, order’s status is in Pending payment.
    Now try “refund” button for an item and proceed to click save.
    Before this, enable a debugger, the code in wc_create_refund
    not check for order’s status , and not check for whether the order was paid !

    I thought Order should be in On-hold or processing, or complete that you
    can do a refund ? It makes no sense that to refund for item that has not been paid.

    woocommerce/includes/wc-order-functions.php, function wc_create_refund().

    function wc_create_refund( $args = array() ) {
    $default_args = array(
    ‘amount’ => 0,
    ‘reason’ => null,
    ‘order_id’ => 0,
    ‘refund_id’ => 0,
    ‘line_items’ => array(),
    ‘refund_payment’ => false,
    ‘restock_items’ => false,
    );

    try {
    $args = wp_parse_args( $args, $default_args );
    $order = wc_get_order( $args[‘order_id’] );

    if ( ! $order ) {
    throw new Exception( __( ‘Invalid order ID.’, ‘woocommerce’ ) );
    }

    • This topic was modified 1 year ago by hiheaven01.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support thup90

    (@thup90)

    Hi there hiheaven01,

    Indeed, the wc_create_refund function doesn’t check for the order status. So we should always check the order status before refunding to customers.

    hiheaven01

    (@hiheaven01)

    hi thup90,

    Would you please show me how to check using which filter/action ?

    It seems like there is no filter/action that I use?

    thanks

    Plugin Support Three Sons

    (@3sonsdevelopment)

    Hi @hiheaven01,

    For orders that have been paid off-line or were created/modified manually, there isn’t a check on the status. If an order was made with a gateway like Stripe, you can only refund via Stripe an amount up to the charged amount.

    With manual changes, the system expects the user to verify that things are correct. Here’s the code for this:

    https://github.com/woocommerce/woocommerce/blob/67663836c0984b87b4dbd6b47a94ea7c4f041b76/includes/wc-order-functions.php#L491

    If you have any questions, please let me know.

    Cheers,

    Plugin Support Three Sons

    (@3sonsdevelopment)

    Hello @hiheaven01,

    It’s been a while since we heard from you, so I’m marking this thread resolved. Hopefully, you’ve been able to resolve this, but if you haven’t, please let open up a new topic and we’ll be happy to help out.

    Take care

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Refund Code does not check for Order’s status or Order has been paid’ is closed to new replies.