本文整理汇总了PHP中WooThemes_Sensei_Utils::sensei_remove_user_from_course方法的典型用法代码示例。如果您正苦于以下问题:PHP WooThemes_Sensei_Utils::sensei_remove_user_from_course方法的具体用法?PHP WooThemes_Sensei_Utils::sensei_remove_user_from_course怎么用?PHP WooThemes_Sensei_Utils::sensei_remove_user_from_course使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WooThemes_Sensei_Utils
的用法示例。
在下文中一共展示了WooThemes_Sensei_Utils::sensei_remove_user_from_course方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sensei_woocommerce_cancel_order
/**
* Runs when an order is cancelled.
* @since 1.2.0
* @access public
* @param integer $order_id order ID
* @return void
*/
public function sensei_woocommerce_cancel_order($order_id)
{
// Get order object
$order = new WC_Order($order_id);
// Run through each product ordered
if (0 < sizeof($order->get_items())) {
// Get order user
$user_id = $order->__get('user_id');
foreach ($order->get_items() as $item) {
$product_type = '';
if (isset($item['variation_id']) && 0 < $item['variation_id']) {
$item_id = $item['variation_id'];
$product_type = 'variation';
} else {
$item_id = $item['product_id'];
}
// End If Statement
$_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type);
// Get courses that use the WC product
$courses = array();
$courses = $this->post_types->course->get_product_courses($item_id);
// Loop and update those courses
foreach ($courses as $course_item) {
// Check and Remove course from courses user meta
$dataset_changes = WooThemes_Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id);
}
// End For Loop
}
// End For Loop
}
// End If Statement
}
示例2: remove_active_course
/**
* Remove active course when an order is refunded or cancelled
* @param integer $order_id ID of order
* @return void
*/
public function remove_active_course($order_id)
{
$order = new WC_Order($order_id);
foreach ($order->get_items() as $item) {
if ($item['product_id'] > 0) {
$user_id = get_post_meta($order_id, '_customer_user', true);
if ($user_id) {
// Get all courses for product
$args = array('posts_per_page' => -1, 'post_type' => 'course', 'meta_query' => array(array('key' => '_course_woocommerce_product', 'value' => $item['product_id'])), 'orderby' => 'menu_order date', 'order' => 'ASC', 'fields' => 'ids');
$course_ids = get_posts($args);
if ($course_ids && count($course_ids) > 0) {
foreach ($course_ids as $course_id) {
// Remove all course user meta
WooThemes_Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
}
// End For Loop
}
// End If Statement
}
// End If Statement
}
// End If Statement
}
// End For Loop
}
示例3: remove_user_from_post
public function remove_user_from_post()
{
global $woothemes_sensei;
$return = '';
// Security check
$nonce = '';
if (isset($_POST['remove_user_from_post_nonce'])) {
$nonce = esc_html($_POST['remove_user_from_post_nonce']);
}
if (!wp_verify_nonce($nonce, 'remove_user_from_post_nonce')) {
die($return);
}
// Parse POST data
$data = $_POST['data'];
$action_data = array();
parse_str($data, $action_data);
if ($action_data['user_id'] && $action_data['post_id'] && $action_data['post_type']) {
$user_id = intval($action_data['user_id']);
$post_id = intval($action_data['post_id']);
$post_type = sanitize_text_field($action_data['post_type']);
$order_id = sanitize_text_field($action_data['order_id']);
$user = get_userdata($user_id);
switch ($post_type) {
case 'course':
$removed = WooThemes_Sensei_Utils::sensei_remove_user_from_course($post_id, $user_id);
if (!empty($order_id) && is_woocommerce_active()) {
$order = new WC_Order($order_id);
if (!empty($order)) {
$order->update_status('cancelled');
}
}
break;
case 'lesson':
$removed = WooThemes_Sensei_Utils::sensei_remove_user_from_lesson($post_id, $user_id);
break;
}
if ($removed) {
$return = 'removed';
}
}
die($return);
}
示例4: remove_user_from_post
public function remove_user_from_post()
{
global $woothemes_sensei;
$return = '';
// Security check
$nonce = '';
if (isset($_POST['remove_user_from_post_nonce'])) {
$nonce = esc_html($_POST['remove_user_from_post_nonce']);
}
if (!wp_verify_nonce($nonce, 'remove_user_from_post_nonce')) {
die($return);
}
// Parse POST data
$data = $_POST['data'];
$action_data = array();
parse_str($data, $action_data);
if ($action_data['user_id'] && $action_data['post_id'] && $action_data['post_type']) {
$user_id = intval($action_data['user_id']);
$post_id = intval($action_data['post_id']);
$post_type = sanitize_text_field($action_data['post_type']);
$user = get_userdata($user_id);
switch ($post_type) {
case 'course':
$removed = WooThemes_Sensei_Utils::sensei_remove_user_from_course($post_id, $user_id);
do_action('sensei_user_course_reset', $user_id, $post_id);
break;
case 'lesson':
$removed = WooThemes_Sensei_Utils::sensei_remove_user_from_lesson($post_id, $user_id);
do_action('sensei_user_lesson_reset', $user_id, $post_id);
break;
}
if ($removed) {
$return = 'removed';
}
}
die($return);
}