array( 'wc-processing', 'wc-completed', 'wc-on-hold' ),
'date_created' => '>=' . strtotime( 'today', current_time( 'timestamp' ) ),
'limit' => 100,
'return' => 'objects',
) );
foreach ( $orders as $order ) {
foreach ( $order->get_items() as $item ) {
$pid = $item->get_variation_id() ? $item->get_product_id() : $item->get_product_id();
if ( (int) $pid === (int) $product_id ) {
$count += (int) $item->get_quantity();
}
}
}
set_transient( $key, $count, 15 * MINUTE_IN_SECONDS );
return $count;
}
/**
* Videos "story" : recupere les videos du dossier FileBird nomme "vidéo-story"
* (ou "video-story"). Memes videos pour tous les produits. Cache 1 h.
* Prerequis : extension gratuite FileBird (dossiers de mediatheque).
*/
function mrdc_get_story_videos() {
$cached = get_transient( 'mrdc_story_videos' );
if ( false !== $cached ) {
return $cached;
}
global $wpdb;
$videos = array();
$folder_table = $wpdb->prefix . 'fbv';
$rel_table = $wpdb->prefix . 'fbv_attachment_folder';
$has_fbv = ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $folder_table ) ) === $folder_table );
if ( $has_fbv ) {
$folder_id = $wpdb->get_var( $wpdb->prepare(
"SELECT id FROM {$folder_table} WHERE name IN (%s, %s) LIMIT 1",
'vidéo-story', 'video-story'
) );
if ( $folder_id ) {
$ids = $wpdb->get_col( $wpdb->prepare(
"SELECT attachment_id FROM {$rel_table} WHERE folder_id = %d",
$folder_id
) );
foreach ( $ids as $aid ) {
if ( 0 !== strpos( (string) get_post_mime_type( $aid ), 'video/' ) ) {
continue;
}
$url = wp_get_attachment_url( $aid );
if ( ! $url ) {
continue;
}
$poster_id = get_post_thumbnail_id( $aid ); // image mise en avant de la video (optionnel)
$videos[] = array(
'url' => $url,
'poster' => $poster_id ? wp_get_attachment_image_url( $poster_id, 'medium' ) : '',
'title' => get_the_title( $aid ),
);
}
}
}
set_transient( 'mrdc_story_videos', $videos, HOUR_IN_SECONDS );
return $videos;
}
get_header( 'shop' );
while ( have_posts() ) :
the_post();
global $product;
if ( ! $product instanceof WC_Product ) {
$product = wc_get_product( get_the_ID() );
}
/* ===== Données produit ===== */
$product_id = $product->get_id();
$title = $product->get_name();
$is_on_sale = $product->is_on_sale();
$price = (float) $product->get_price();
$regular = (float) $product->get_regular_price();
$discount_pct = ( $is_on_sale && $regular > 0 && $price < $regular ) ? round( 100 - ( $price / $regular * 100 ) ) : 0;
$rating_avg = (float) $product->get_average_rating();
$rating_count = (int) $product->get_review_count();
$total_sales = (int) get_post_meta( $product_id, 'total_sales', true );
$stock_qty = $product->get_stock_quantity();
// Marque : attribut pa_marque sinon 1re catégorie
$brand = '';
$brand_terms = wc_get_product_terms( $product_id, 'pa_marque', array( 'fields' => 'names' ) );
if ( ! empty( $brand_terms ) ) {
$brand = $brand_terms[0];
} else {
$cats = wc_get_product_terms( $product_id, 'product_cat', array( 'fields' => 'names' ) );
$brand = ! empty( $cats ) ? $cats[0] : '';
}
// Catégorie principale pour le fil d'Ariane
$main_cat = null;
$cat_ids = $product->get_category_ids();
if ( ! empty( $cat_ids ) ) {
$main_cat = get_term( $cat_ids[0], 'product_cat' );
}
// Galerie : image mise en avant + galerie
$image_ids = array();
if ( $product->get_image_id() ) {
$image_ids[] = (int) $product->get_image_id();
}
foreach ( $product->get_gallery_image_ids() as $gid ) {
$image_ids[] = (int) $gid;
}
$image_ids = array_slice( array_unique( $image_ids ), 0, 5 );
// Lien WhatsApp prérempli
$wa_text = rawurlencode( 'Bonjour, je veux commander : ' . $title . ' (' . wp_strip_all_tags( wc_price( $price ) ) . ') · ' . get_permalink( $product_id ) );
$wa_url = 'https://wa.me/' . $mrdc_whatsapp . '?text=' . $wa_text;
// Barre de stock (vente flash)
$stock_pct = null;
if ( null !== $stock_qty && $stock_qty > 0 ) {
$stock_pct = max( 8, min( 96, round( $total_sales / max( 1, $total_sales + $stock_qty ) * 100 ) ) );
}
// Fin de promo : vraie date Woo si definie, sinon fin de journee (heure du site)
$sale_end = $product->get_date_on_sale_to();
if ( $sale_end instanceof WC_DateTime ) {
$sale_end_ts = $sale_end->getTimestamp();
} else {
// Fin de journee, heure locale du site, convertie en timestamp UTC
$sale_end_ts = strtotime( date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) ) ) - (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
}
// Vendus aujourd'hui : vraies commandes du jour contenant ce produit (cache 15 min)
$sold_today = mrdc_get_sold_today( $product_id );
// Viewers : simule mais stable par produit (seed = ID), varie legerement dans la journee
$viewers_base = 12 + ( $product_id % 11 ) + (int) ( date( 'G' ) / 3 );
?>
Commander sur WhatsApp
'publish',
'limit' => 4,
'orderby' => 'date',
'order' => 'DESC',
'include' => wc_get_product_ids_on_sale(),
'exclude' => array( $product_id ),
) );
if ( ! empty( $flash ) ) :
?>
';
comments_template();
echo '';
}
?>
Commander
1 ) : ?>
$img_id ) : ?>
0 ) : ?>
-%
0 ) : ?>
( avis)
is_in_stock() ) : ?>
En stock à Kinshasa
Rupture de stock
0 ) : ?>
⚡ vendus aujourd'hui
0 ) : ?>
vendus
personnes regardent ce produit
⚡ Vente Flash
Se termine dans
00:00:00
$price ) : ?>
-%
Plus que en stock à ce prix
Livraison rapide : Kinshasa le jour même, provinces 24-72h
Payez à la livraison : cash ou Mobile Money (M-Pesa, Orange, Airtel)
Testé devant vous : produit vérifié à la livraison, garanti 12 mois
Nos produits en vidéo
StoriesCaractéristiques
get_attributes(); if ( ! empty( $attributes ) ) : ?>
get_visible() ) { continue; }
$label = wc_attribute_label( $attribute->get_name() );
if ( $attribute->is_taxonomy() ) {
$values = wc_get_product_terms( $product_id, $attribute->get_name(), array( 'fields' => 'names' ) );
} else {
$values = $attribute->get_options();
}
$row++;
?>
Aucune caractéristique renseignée.
Description
⚡ Vente FlashPrix cassés · quantités limitées
get_regular_price(); $fpc = (float) $fp->get_price();
$fpct = ( $fr > 0 && $fpc < $fr ) ? round( 100 - $fpc / $fr * 100 ) : 0;
?>
0 ) : ?>-%
get_image( 'woocommerce_thumbnail', array( 'style' => 'width:100%;height:100%;object-fit:cover' ) ); ?>
get_name() ); ?>
0 ) : ?>
get_image( 'thumbnail', array( 'style' => 'width:100%;height:100%;object-fit:cover' ) ); ?>
personnes regardent ce produit
