plugins - Problem with add_action

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

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!

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!

Share Improve this question asked Dec 30, 2019 at 18:26 AmirAmir 656 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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/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 );
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744870482a4598231.html

相关推荐

  • plugins - Problem with add_action

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

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信