Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function htdat_shortcode_atts_products( $out, $pairs, $atts, $shortcode ) {
- if ( isset ( $atts[ 'is_new' ] ) && $atts [ 'is_new' ] ) {
- $out[ 'is_new' ] = true;
- } else {
- $out[ 'is_new' ] = false;
- }
- return $out;
- }
- add_filter('shortcode_atts_products', 'htdat_shortcode_atts_products', 10, 4);
- function htdat_woocommerce_shortcode_products_query( $query_args, $attributes ) {
- if ( $attributes[ 'is_new' ] ) {
- $today = getdate();
- $days_ago = 30;
- $query_args[ 'date_query' ] = array ('after' => date( 'Y-m-d', strtotime( '-' . $days_ago . ' days', strtotime( $today['year'] . '-' . $today['mon'] . '-' . $today['mday'] ) ) ),);
- }
- return $query_args;
- }
- add_filter( 'woocommerce_shortcode_products_query', 'htdat_woocommerce_shortcode_products_query', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement