Comments 2Jack started the conversationOctober 11, 2024 at 3:35amHi,I would like to display the hidden product list using woo product shortcut as below script:[products category="activewear" visibility="hidden" ]But the the hidden products can not be displayed since Product Time active set hidden.Please help & thanks,Jack 1,226Dustin repliedOctober 11, 2024 at 4:07amHi Jack, Please add the custom code below. (How to add custom code? ↗): add_filter( 'woocommerce_shortcode_products_query_results', function ( $results, $shortcode ) { if ( ! class_exists( 'WPCleverWoopt' ) ) { return $results; } $attrs = $shortcode->get_attributes(); if ( ! empty( $attrs['visibility'] ) && ( $attrs['visibility'] === 'hidden' ) ) { global $wpdb; $hidden = []; $products = $wpdb->get_results( "SELECT id FROM $wpdb->posts WHERE post_type = 'product' AND post_status = 'publish' LIMIT 500", OBJECT ); if ( count( $products ) > 0 ) { foreach ( $products as $pr ) { if ( ! WPCleverWoopt::woopt_is_visible( true, $pr->id ) ) { array_push( $hidden, $pr->id ); } } $results->ids = array_unique( array_merge( $results->ids, $hidden ) ); } } return $results; }, 99, 2 ); Then, hidden products set by Timer will be displayed on that shortcode.Best regards,Dustin 2Jack repliedOctober 11, 2024 at 6:10amHi Dustin,I tested the script and found the results variable is correct but can not display any products.The total, total_pages.. are 0?$results array is as below:stdClass Object ( [ids] => Array ( [0] => 1659 [1] => 1683 [2] => 1751 [3] => 1770 [4] => 1772 [5] => 1774 [6] => 1846 [7] => 1795 [8] => 1777 [9] => 1797 [10] => 1817 [11] => 1809 [12] => 1800 [13] => 1802 [14] => 1804 [15] => 1760 [16] => 1713 [17] => 1711 [18] => 1762 [19] => 1768 [20] => 1852 [21] => 1850 [22] => 1813 [23] => 1944 [24] => 1848 [25] => 1805 [26] => 1727 [27] => 1861 [28] => 1764 [29] => 1859 [30] => 1686 [31] => 1684 [32] => 1688 [33] => 1720 [34] => 1821 [35] => 1823 [36] => 1679 [37] => 1842 [38] => 1867 [39] => 1865 [40] => 1885 ) [total] => 0 [total_pages] => 1 [per_page] => 80 [current_page] => 1 )Please help,Jack 1,226Dustin repliedOctober 11, 2024 at 2:53pmPlease try a new one: add_filter( 'woocommerce_shortcode_products_query_results', function ( $results, $shortcode ) { if ( ! class_exists( 'WPCleverWoopt' ) ) { return $results; } $attrs = $shortcode->get_attributes(); if ( ! empty( $attrs['visibility'] ) && ( $attrs['visibility'] === 'hidden' ) ) { global $wpdb; $hidden = []; $products = $wpdb->get_results( "SELECT id FROM $wpdb->posts WHERE post_type = 'product' AND post_status = 'publish' LIMIT 500", OBJECT ); if ( count( $products ) > 0 ) { foreach ( $products as $pr ) { if ( ! WPCleverWoopt::woopt_is_visible( true, $pr->id ) ) { array_push( $hidden, $pr->id ); } } $results_ids = array_unique( array_merge( $results->ids, $hidden ) ); $results->ids = $results_ids; $results->total = count( $results_ids ); $results->total_pages = ceil( count( $results_ids ) / $results->per_page ); } } return $results; }, 99, 2 );Best regards,Dustin 2Jack repliedOctober 12, 2024 at 5:10amHi Dustin,It also not display any products.I try some test and found the <woocommerce_shortcode_products_query_results> hook only can filter out the $results products but can not add any other products.Just FYRPlease help again & thanks,Jack Sign in to reply ...
Hi,
I would like to display the hidden product list using woo product shortcut as below script:
[products category="activewear" visibility="hidden" ]
But the the hidden products can not be displayed since Product Time active set hidden.
Please help & thanks,
Jack
Hi Jack,
Please add the custom code below. (How to add custom code? ↗):
Then, hidden products set by Timer will be displayed on that shortcode.
Best regards,
Dustin
Hi Dustin,
I tested the script and found the results variable is correct but can not display any products.
The total, total_pages.. are 0?
$results array is as below:
stdClass Object ( [ids] => Array ( [0] => 1659 [1] => 1683 [2] => 1751 [3] => 1770 [4] => 1772 [5] => 1774 [6] => 1846 [7] => 1795 [8] => 1777 [9] => 1797 [10] => 1817 [11] => 1809 [12] => 1800 [13] => 1802 [14] => 1804 [15] => 1760 [16] => 1713 [17] => 1711 [18] => 1762 [19] => 1768 [20] => 1852 [21] => 1850 [22] => 1813 [23] => 1944 [24] => 1848 [25] => 1805 [26] => 1727 [27] => 1861 [28] => 1764 [29] => 1859 [30] => 1686 [31] => 1684 [32] => 1688 [33] => 1720 [34] => 1821 [35] => 1823 [36] => 1679 [37] => 1842 [38] => 1867 [39] => 1865 [40] => 1885 ) [total] => 0 [total_pages] => 1 [per_page] => 80 [current_page] => 1 )
Please help,
Jack
Please try a new one:
Best regards,
Dustin
Hi Dustin,
It also not display any products.
I try some test and found the <woocommerce_shortcode_products_query_results> hook only can filter out the $results products but can not add any other products.
Just FYR
Please help again & thanks,
Jack