Skip to content

Instantly share code, notes, and snippets.

@em-piguet
Created May 9, 2022 12:26
Show Gist options
  • Save em-piguet/c9db67c7856ce39872a4f7ff4bd5a60e to your computer and use it in GitHub Desktop.
Save em-piguet/c9db67c7856ce39872a4f7ff4bd5a60e to your computer and use it in GitHub Desktop.
If the post is a gift to the users, we remove the restriction on post content during 7 days
<?php
function acces_article_offert()
{
// only on post
if (is_singular('post')) {
// get the gift start date
$date_de_debut = get_field('article_gift');
if ($date_de_debut) {
$date_de_fin = date('Y-m-d', strtotime($date_de_debut . ' + 7 days'));
$date_now = date('Y-m-d');
if ($date_de_fin >= $date_now && $date_now >= $date_de_debut) {
// remove restriction for this post !
if (function_exists('wc_memberships') && version_compare(\WC_Memberships::VERSION, '1.9.0', '>=') && is_singular('post')) {
// This doesn't work anymore !
remove_action('the_post', array(wc_memberships()->get_restrictions_instance()->get_posts_restrictions_instance(), 'restrict_post'), 0);
}
// display a message
add_action('affiche_un_message', __NAMESPACE__ . '\\article_offert');
}
}
}
}
add_action('wp_head', __NAMESPACE__ . '\\acces_article_offert', 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment