I am making a booking site, where cabins are a custom post. Users pay with Woocommerce subscription to have their cabins visible on the site.
Therefore, I need to check if the user have an active subscription in order to publish the post(s) created.
Currently, I check if the user have an active subscription like so:
if (has_woocommerce_subscription('','','active')) {
While this works, it is clearly not changing the post status.
So my question is, how do I get the current user, the users posts id, the status etc., and change the post status to published?
I found this in another thread, although, it changes the post status from published to draft, so I'm guessing it could be similar?
add_action('publish_post', 'check_user_publish', 10, 2);
function check_user_publish ($post_id, $post) {
$user_id = get_current_user_id();
if ($user_id != $post->post_author)
return;
$query = array(
'ID' => $post_id,
'post_status' => 'draft',
);
wp_update_post( $query, true );
}}
Ideally, this check should be run maybe once a day if possible?
Thanks