ACF Field Expiry with date (May be after 30 days)

Hi,

We have created Badge named New with ACF field. Now, we want to set expiry to this filed so that the Badge named New get disappeared (or removed) after certain days (Let’s say after 30 days of product published).

We have used below code for New Badge with ACF at functions.php

add_action( 'woocommerce_product_thumbnails', 'hnpl_display_acf_field_under_images', 20 );
function hnpl_display_acf_field_under_images() {
  if(get_field('product_new')){
  echo '<div class="hnpl-badge product-new"><strong>'.get_field('product_new').'</strong></div>';
 }
}

Hoping for the solution.

Thank You,
Bibhash Karn

Hello Bibhash,

Thanks for writing in! You will need to perform a date comparison as a condition so that the new badge will be displayed when the condition is true.

function my_function_name(){
    IF the_product_new is not null AND Date > 30 days THEN
             Display the badge
     ENDIF
}

Perhaps this PHP Date comparison can help you:

Be advised that custom PHP Coding is beyond the scope of our support under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.