0

I have a function that i need to run every time a subscription status changes to active, This is my code:

add_action( 'woocommerce_subscription_status_active', array( __CLASS__,'add_subscription_course_access' ) );
public static function add_subscription_course_access( $order )
    {

    $products = $order->get_items();
    $customer_id = $order->get_customer_id();

    $courses_id = get_field('user-programs', 'user_'. $customer_id);
    $courses_id = str_replace("[","",$courses_id);
    $courses_id = str_replace("]","",$courses_id);
    $courses_id = explode(",",$courses_id);

    foreach ( $courses_id as $course_id ) {
        ld_update_course_access( $customer_id, $course_id );
    }
}

It works on localhost but on a live site its not working!

1

Yo don't properly call the callback function.

If you want to code on oriented object programmation, you have to create your class, and construct function with add_action...

Here more informations about it : https://wordpress.stackexchange.com/a/48094/9716

or you do something like this (its no POO but its working as well).

add_action( 'woocommerce_subscription_status_active', 'add_subscription_course_access' ) );
function add_subscription_course_access( $order )
    {

    $products = $order->get_items();
    $customer_id = $order->get_customer_id();

    $courses_id = get_field('user-programs', 'user_'. $customer_id);
    $courses_id = str_replace("[","",$courses_id);
    $courses_id = str_replace("]","",$courses_id);
    $courses_id = explode(",",$courses_id);

    foreach ( $courses_id as $course_id ) {
        ld_update_course_access( $customer_id, $course_id );
    }
}
| improve this answer | |
  • Thanks, but still it's not working. As i said it works in my system localhost but on website it's not working – Amir Dec 31 '19 at 4:45
  • I figured it out, It was a problem of getting user-programs field, Thanks – Amir Dec 31 '19 at 5:30
  • Oh yes sorry... cool if you solved your issue ;-) – Vincent Guesné Jan 3 at 16:15
  • Oh yes sorry... cool if you solved your issue ;-) – Vincent Guesné Jan 3 at 16:16
  • Oh yes sorry... cool if you solved your issue ;-) – Vincent Guesné Jan 3 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.