Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. function htdat_shortcode_atts_products( $out, $pairs, $atts, $shortcode ) {
  2. if ( isset ( $atts[ 'is_new' ] ) && $atts [ 'is_new' ] ) {
  3. $out[ 'is_new' ] = true;
  4. } else {
  5. $out[ 'is_new' ] = false;
  6. }
  7.  
  8. return $out;
  9. }
  10. add_filter('shortcode_atts_products', 'htdat_shortcode_atts_products', 10, 4);
  11.  
  12. function htdat_woocommerce_shortcode_products_query( $query_args, $attributes ) {
  13. if ( $attributes[ 'is_new' ] ) {
  14. $today = getdate();
  15. $days_ago = 30;
  16. $query_args[ 'date_query' ] = array ('after' => date( 'Y-m-d', strtotime( '-' . $days_ago . ' days', strtotime( $today['year'] . '-' . $today['mon'] . '-' . $today['mday'] ) ) ),);
  17. }
  18.  
  19. return $query_args;
  20. }
  21. add_filter( 'woocommerce_shortcode_products_query', 'htdat_woocommerce_shortcode_products_query', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement