Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somewherewarm-snippets/5d54c5d30c1dcbd7bb66f9c5cf3293ea to your computer and use it in GitHub Desktop.
Save somewherewarm-snippets/5d54c5d30c1dcbd7bb66f9c5cf3293ea to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: WooCommerce Gift Cards
* Plugin URI: https://woocommerce.com/products/gift-cards/
* Description: Use this snippet to set a specific expiration date for all gift cards created on your store
* Version: 1.0
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Developer: Jason Kytros
*
*
* Copyright: © 2020 Jason Kytros
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_filter( 'woocommerce_gc_create_order_giftcard_args', 'sw_gc_set_custom_expiry_date', 10, 4 );
function sw_gc_set_custom_expiry_date( $args, $_product, $order_item, $order ) {
$base = 0 === $args['deliver_date'] ? time() : $args['deliver_date'];
$base_datetime = new DateTime();
// year, month, date.
$base_datetime->setDate( '2021', '10', '10' );
$args[ 'expire_date' ] = $base_datetime->getTimestamp();
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment