Compare“Modern Canvas Paintings to Decorate Any Room” has been added to the compare list
1289Products Found
add_action('my_telegram_cron', 'send_product_to_telegram'); function send_product_to_telegram() { if (!function_exists('wc_get_products')) return; $args = [ 'limit' => 1, 'status' => 'publish', 'meta_query' => [ [ 'key' => '_posted_to_telegram', 'compare' => 'NOT EXISTS' ] ] ]; $products = wc_get_products($args); if (empty($products)) return; $product = $products[0]; $product_id = $product->get_id(); $title = $product->get_name(); $price = $product->get_price(); $link = get_permalink($product_id); $description = wp_strip_all_tags($product->get_short_description()); if (empty($description)) { $description = "π₯ Best deal available! Check now."; } $description = substr($description, 0, 120) . "..."; $hashtags = generate_hashtags($title); $bot_token = "8392248247:AAG7ca87KY7dVJCyIbvKV7Z4du5kGTiKZnU"; $chat_id = "-1003757549944"; // πΌοΈ MULTIPLE IMAGES (gallery + featured) $image_ids = $product->get_gallery_image_ids(); array_unshift($image_ids, $product->get_image_id()); // featured first $media = []; $i = 0; foreach ($image_ids as $img_id) { $img_url = wp_get_attachment_url($img_id); if (!$img_url) continue; $item = [ 'type' => 'photo', 'media' => $img_url ]; // first image = caption if ($i == 0) { $caption = "π " . esc_html($title) . "\n\n"; $caption .= "π° Price: βΉ" . esc_html($price) . "\n\n"; $caption .= "π " . esc_html($description) . "\n\n"; $caption .= esc_html($hashtags); $item['caption'] = $caption; $item['parse_mode'] = 'HTML'; } $media[] = $item; $i++; if ($i >= 5) break; // max 5 images } // πΈ Send media group (carousel) wp_remote_post("https://api.telegram.org/bot$bot_token/sendMediaGroup", [ 'body' => [ 'chat_id' => $chat_id, 'media' => json_encode($media) ] ]); // π INLINE BUTTON MESSAGE (separate message) $button = [ 'inline_keyboard' => [ [ [ 'text' => 'π Buy Now', 'url' => $link ] ] ] ]; wp_remote_post("https://api.telegram.org/bot$bot_token/sendMessage", [ 'body' => [ 'chat_id' => $chat_id, 'text' => "π Buy this product now", 'reply_markup' => json_encode($button) ] ]); // mark as posted update_post_meta($product_id, '_posted_to_telegram', 'yes'); }