每次订阅状态更改为活动时,我都需要运行一个函数,这是我的代码:
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 );
}
}
它在本地主机上工作,但在实时站点上不工作!
最合适的回答,由SO网友:Vincent Guesné 整理而成
你没有正确调用回调函数。
如果你想在面向对象编程上编码,你必须创建你的类,并用add\\u action构造函数。。。
以下是有关它的更多信息:https://wordpress.stackexchange.com/a/48094/9716
或者你做了这样的事情(没有大便,但也很有效)。
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 );
}
}