• Hello,
    First of all thank you for your awesome plugin. It works perfectly!

    I have a question though, I created a script that allows me to create custom product programmatically. The problem is that when I create a product programmatically, the expiration date will not be set. Instead, if I create the product (woocommerce of course) manually on wordpress, the expiration date works as expected.

    The only way to make a product created programmatically to expire, is to manual update the product itself on WordPress.

    My question, in other word is: how can I set the expiration date via code programmatically once I created my custom product? Or, is there a way to make it happens via WordPress?

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hey, the plugin has a problem with script calls to create new posts. This problem extends for Rest API usage too.
    I made a simple customization in plugin. Add in post-expirator.php (anywhere) an action:

    add_action('post_expirator_event','_scheduleExpiratorEvent',1,3);

    So, in my own code I call the action:

    
    //get the custom Post Expirator settings 
    $expire_custom = get_option('expirationdateDefaultDateCustom');			
    
    //create a date based on settings
    $expire_date = date( 'Y-m-d H:i:s', strtotime($expire_custom, current_time( 'timestamp', 0 )));
    
    //convert to GMT (Post Expirator uses in this way)
    $ts = get_gmt_from_date($expire_date,'U');
    
    //create the options as you need (I don't know all options available), in my case works
    $opts = array();
    $opts['expireType'] = 'delete';
    $opts['id'] = $post_id;
    
    //call the action and be happy!
    do_action('post_expirator_event',$post_id,$ts,$opts);
    
    • This reply was modified 6 years, 8 months ago by pesseba.
    Thread Starter crasholino

    (@crasholino)

    Man this code works perfectly! Thank you very much!!!

    Thread Starter crasholino

    (@crasholino)

    @pesseba, I just noticed, after months that the code worked pretty good, that the code is not working anymore.

    I mean, your code creates the expiration date, but it doesn’t expire at all :\
    … Any suggestions?

    • This reply was modified 6 years, 4 months ago by crasholino.

    @crasholino did you ever get it working again?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Post Expiration via code’ is closed to new replies.