Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hamidrezayazdani/4fb2fc75759b04884fd8367777d035e8 to your computer and use it in GitHub Desktop.
Save hamidrezayazdani/4fb2fc75759b04884fd8367777d035e8 to your computer and use it in GitHub Desktop.
کد کوتاه نمایش محصولات بر اساس تاریخ آخرین ویرایش در ووکامرس
<?php
function ywp_date_modified_wc_product_shortcode( $args, $atts ){
$atts = shortcode_atts(
array(
'orderby' => 'date',
'interval' => '20',
), $atts, 'bartag'
);
if ( 'date_modified' === esc_attr( $atts['orderby'] ) ) {
$args['date_query'] = array(
array(
'column' => 'post_modified',
'after' => (int) $atts['interval'] . ' days ago',
'inclusive' => true,
),
);
}
return $args;
}
add_filter( 'woocommerce_shortcode_products_query', 'ywp_date_modified_wc_product_shortcode', 10, 2 );
// The code goes to functions.php file of your active theme (or child theme)
// How to use? Like this: [products orderby="date_modified" interval="15"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment