How to show raffle countdown on product page?
Watch video from youtube. See the code below.
Countdown plugin:
You need the shortcode [raffle name=’info’ id=’0′ productid=” tags=”] pasted in the short description of the product, or any other place of the product page.
For productid=”” add your product id, found in the url. eg: [raffle name=’info’ id=’0′ productid=’555′ tags=”]
Next, you need the following code in the functions.php of your Child theme (!!! important!!!)
add_filter( 'raffle_info_filter', 'custom_raffle_function', 10, 2 );function custom_raffle_function( $content, $raffle_arr ){// $raffle_obj is of type associative array and it has the following keys// $raffle_id = $raffle_obj['raffle_id']; //raffle id$raffle_name = $raffle_arr['raffle_name']; //raffle name$start_ticket = $raffle_arr['start_ticket']; //raffle starting number$limit_tickets = $raffle_arr['limit_tickets']; //number of total tickets if not 'unlimited', else number$sold_tickets = $raffle_arr['sold_tickets']; //number of sold tickets$last_sold_ticket = $raffle_arr['last_sold_ticket']; //last sold ticket$last_sold_prefixed = $raffle_arr['last_sold_prefixed']; //last sold with prefix$prefix = $raffle_arr['prefix']; //prefix $start_datetime = $raffle_arr['start_datetime']; //1690911878, 0$end_datetime = $raffle_arr['end_datetime']; //1690921878$start_date_string = $raffle_arr['start_date_string']; //Tue, 01 Aug 2023 17:44:36 GMT$end_date_string = $raffle_arr['end_date_string'];$is_terminated = $raffle_arr['is_terminated']; // true/false$is_raffle = $raffle_arr['is_raffle']; $tags = $raffle_arr['tags'];$productid = $raffle_arr['productid'];if( $is_terminated){add_filter("woocommerce_is_purchasable", "__return_false");return '<div> Raffle has finished</div>';}if( ! $is_raffle ){return '<div> This is not a raffle </div>';}$pro_custom = strpos( $tags, 'pro-custom') !== false;$time_now = time();$started = false;if( $start_datetime ){if( $start_datetime > $time_now ){//raffle hasn't started yet $content .= "<div> Raffle will start in </div>";$content .= do_shortcode("[gpls_wpsctr_quick_countdown id='inkfufyj22' datetime='${start_datetime}']");$started = true;}}if( ! $started && $end_datetime ){if( $end_datetime > $time_now ){global $raffle_enddatetime;$raffle_enddatetime = $end_datetime;add_action('woocommerce_after_add_to_cart_form', function(){global $raffle_enddatetime;echo "<div> Raffle will end in </div>";echo do_shortcode("[gpls_wpsctr_quick_countdown id='inkfufyj' datetime='${raffle_enddatetime}']");});}}if( $pro_custom ){$content .= "<div> You are in a custom page product </div>";}return $content;}