0

I've created a plugin related to woocommerce then created a shortcode in a class. And in my class is these:

class MyShortcode 
{
    /**
     * Register services and applications
     */
    public function register()
    {
        add_shortcode('myshortcode', [$this, 'basket']);
        add_action('wp_enqueue_scripts', [$this, 'activitiesEnqueueStyles']);
        add_action('woocommerce_review_order_after_payment', [$this, 'action_function_name_2183', 10, 3]);
    }

    /**
     * Enqueue styles and scripts
     */
    public function activitiesEnqueueStyles()
    {
        wp_enqueue_style('basket', $this->plugin_url . 'assets/lib/basket.min.css');
    }

    public function action_function_name_2183( $order_id, $posted_data, $order )
    {
        var_dump('here');
        var_dump($order_id);
        exit;
    }

I wanted to retrieve the order id after placing order or payment which is the hook add_action( 'woocommerce_review_order_after_payment', [$this, 'action_function_name_2183', 10, 3] ); but it is completely ignored whenever I try to submit the payment form.

I've been reading this guide to check the hooks and tried some of them which actually works but for some reason, only this hook woocommerce_review_order_after_payment is not working on my end.

Currently, got no idea why it's not working. The other action hooks are working aside from woocommerce hooks. I'm not sure if there is anything I need to do before using the hooks.

If there are any related links to this, you can link them below, as I've tried looking for something related to this but can't find any.

7uc1f3r
  • 28,449
  • 17
  • 32
  • 50
the_lorem_ipsum_guy
  • 452
  • 1
  • 12
  • 27
  • 2
    The `woocommerce_review_order_after_payment` action hook [is in an if condition](https://github.com/woocommerce/woocommerce/blob/b19500728b4b292562afb65eb3a0c0f50d5859de/templates/checkout/payment.php#L59-L61). Maybe that's where "your problem" is – 7uc1f3r Jun 10 '21 at 10:52
  • 2
    p.s. also know that this action hook does not contain 3 but 0 arguments, so it looks like you are using the wrong hook for what you want to perform AND while I edited your question I believe you confusing the `woocommerce_review_order_after_payment` and the `woocommerce_checkout_order_processed` hooks – 7uc1f3r Jun 10 '21 at 11:27
  • thanks @7uc1f3r I will give it a try doing an ajax call. Just want to know if which hook should I be using to get the order id? Is it the `woocommerce_checkout_order_processed`? – the_lorem_ipsum_guy Jun 10 '21 at 12:00
  • It depends on what you want to do specifically. [woocommerce_checkout_order_processed](https://stackoverflow.com/a/65673677/11987538) does indeed contain the order_id. Another hook containing the order_id after payment execution is [woocommerce_thankyou](https://stackoverflow.com/a/65806139/11987538). There are several hooks that already contain the order_id, as I already mentioned, it depends on what you specifically want to do when. – 7uc1f3r Jun 10 '21 at 12:05
  • @7uc1f3r my plan is to get the `order_id` after the payment, and to replace the new order email template because I have to add our query and that relates to the `order_id`. So, will try to use the hook `woocommerce_thankyou` since I've tried the `woocommerce_checkout_order_processed` and didn't get any results. – the_lorem_ipsum_guy Jun 10 '21 at 13:23

0 Answers0