• Resolved josssv

    (@josssv)


    Hi! I have been looking into adding specific fees when processing a refund, for example, a cancellation fee to be added manual and which should be deducted from the amount to be refunded. These fees could be then shown in the email the customer gets so it is all well specified.

    I have not found hooks or “easy” methods to create such functionality. It would be great to get some advice or guidance on how to achieve that, and it would even be greater if such hooks could be in place in later versions.

    In a nutshell, I am trying the following:

    1. add_action( ‘admin_enqueue_scripts’, ‘enqueue_custom_refund_script’ );
      The function enqueue_custom_refund_script checks whether I am in the admin, Edit Order. If that is the case, then I enqueue a js: wp_enqueue_script( ‘custom-refund-fields’, get_template_directory_uri() . ‘/js/custom-refund-fields.js’, array( ‘jquery’ ), ‘1.0’, true );
    2. custom-refund-fields.js
      Shows the fields I want to add when the button “refund” is clicked
    3. Additional functionality is added to perform the calculations etc.

    The main problem I have is actually with 1.
    I am using $screen = get_current_screen(); to find out if this is a “shop_order” as post_type. So I wonder if the following: if ( $screen && ‘shop_order’ === $screen->post_type ) { … }, is sufficient to decide enqueuing the js. I find it a bit unorthodox to use this method, but it may be ok?

    As said, some guidance would be nice.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @josssv

    Your approach to adding a custom refund script is technically correct. However, it’s important to note that the method you use to check if you’re on the “Edit Order” page might not be the most reliable.

    The admin_enqueue_scripts hook is not specific to the “Edit Order” page; it runs on every admin page. Therefore, using get_current_screen within this hook is not the best practice because it might not always return the expected results.

    Though writing or providing custom code is not within the scope of our support policy, here is an example:

    add_action( 'load-shop_order', 'enqueue_custom_refund_script' );

    function enqueue_custom_refund_script() {
    wp_enqueue_script( 'custom-refund-fields', get_template_directory_uri() . '/js/custom-refund-fields.js', array( 'jquery' ), '1.0', true );
    }

    If you still have problems or need further assistance on custom coding, we recommend asking development questions on the #developers channel of the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question.

    Regarding your request to add hooks in future versions, we appreciate your feedback. It would be great if you added your ideas as an enhancement request, which is where developers go to look for future plugin features and improvements.

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

    Thread Starter josssv

    (@josssv)

    Thank you!

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @josssv

    I’m glad we were able to help! I will mark this thread as resolved. Should you have further inquiries, kindly create a new topic here.

    Meanwhile, if it isn’t too much to ask for – would you mind leaving us a review here?

    It only takes a couple of minutes but helps us tremendously. It would mean so much to us and would go a really long way.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.