Compare“Beautiful Canvas Prints to Complement Your Home Design” has been added to the compare list
“Beautiful Canvas Prints to Complement Your Home Design” was added to the compare list
1289Products Found
add_action('my_telegram_cron', 'send_product_to_telegram'); function send_product_to_telegram() { $args = [ 'limit' => 1, 'status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', ]; $products = wc_get_products($args); if (empty($products)) return; $product = $products[0]; // Product data $title = $product->get_name(); $price = $product->get_price(); $link = get_permalink($product->get_id()); $description = wp_strip_all_tags($product->get_short_description()); // Short description limit $description = substr($description, 0, 120) . "..."; // Hashtags generate $hashtags = generate_hashtags($title); // Message format $message = "π *" . $title . "*\n\n"; $message .= "π° Price: βΉ" . $price . "\n\n"; $message .= "π " . $description . "\n\n"; $message .= "π Buy Now: " . $link . "\n\n"; $message .= $hashtags; $bot_token = "8392248247:AAG7ca87KY7dVJCyIbvKV7Z4du5kGTiKZnU"; $chat_id = "-1003757549944"; $url = "https://api.telegram.org/bot$bot_token/sendMessage"; wp_remote_post($url, [ 'body' => [ 'chat_id' => $chat_id, 'text' => $message, 'parse_mode' => 'Markdown' ] ]); } // Hashtag function function generate_hashtags($text) { $words = explode(" ", strtolower($text)); $hashtags = ""; foreach ($words as $word) { $word = preg_replace('/[^a-z0-9]/', '', $word); if (strlen($word) > 3) { $hashtags .= "#" . $word . " "; } } // extra common tags $hashtags .= "#shopping #deals #onlineshopping #offer"; return $hashtags; } // Schedule every 4 hours add_filter('cron_schedules', function($schedules) { $schedules['every_four_hours'] = [ 'interval' => 14400, // 4 hours 'display' => 'Every 4 Hours' ]; return $schedules; }); // Schedule event if (!wp_next_scheduled('my_telegram_cron')) { wp_schedule_event(time(), 'every_four_hours', 'my_telegram_cron'); }