Execute custom function after purchase a course/complete an order in LearnPress?

1.5k Views Asked by At

I need to execute a function immediately when someone purchases a course or an order gets completed successfully. The function I am trying to execute is actually called an API. I don't see an appropriate Hook from LearnPress.

It works perfectly when I use "user_register"(when someone registers this hook fire) hook but it doesn't work when I use this "learn_press_confirm_order" hook given by LearnPress.

Do you guys know is there any appropriate way that I can follow and achieve this. Thank You for your time

1

There are 1 best solutions below

1
On

First off, your Lime API key should be treated as a password - don't share it on the web! Go to your LimeLM Account right now, choose 'Settings', and choose 'Generate New Key'. I'll wait :)

There's nothing obviously wrong with your code, so I would debug it like this:

  1. Put a die('setup'); immediately after the add_action. We want to be sure that this file is actually being called. If it is, remove the die.

  2. Wordpress and LearnPress are fantastic, because you've got the source code. Go to wp-content/plugins/learnpress and type (on Linux or something *nix)

    grep -R "learn_press_confirm_order" .

    This will show you all the files that reference this action. There is only one:

    ./templates/order/confirm.php: transaction_method, $order->get_id() ); ?>

    So pull up an editor and edit wp-content/plugins/learnpress/templates/order/confirm.php. You need to determine:

    1. Whether the file is being run at all when you order. (Use die right at the top, or error_log if you can see your webserver/php log files.)

    2. I'm fairly certain at this point you will have found the error, but there's a chance for some reason you're getting to this page, but the action isn't being called. So you might need to work out the exact flow of control on this confirm.php page. Again, die or error_log.

You can make live changes to the code of learnpress, to help you debug it. Most people are afraid to dig into other people's code, but that's the great power of open source. You can just reinstall learnpress when you're done.

Looking forward to hearing how it goes :)