<?php
add_action(« wp_enqueue_scripts », « wp_child_theme »);
function wp_child_theme()
{
if((esc_attr(get_option(« wp_child_theme_setting »)) != « Yes »))
{
wp_enqueue_style(« parent-stylesheet », get_template_directory_uri(). »/style.css »);
}
wp_enqueue_style(« child-stylesheet », get_stylesheet_uri());
wp_enqueue_script(« child-scripts », get_stylesheet_directory_uri() . « /js/scripts.js », array(« jquery »), « 6.1.1 », true);
}
if(!function_exists(« uibverification »))
{
function uibverification()
{
if((esc_attr(get_option(« wp_child_theme_setting_html »)) != « Yes »))
{
if((is_home()) || (is_front_page()))
{
?><meta name= »uib-verification » content= »B811F54AE504A551D8F7292830ACD16E »><?php
}
}
}
}
add_action(« wp_head », « uibverification », 1);
function wp_child_theme_register_settings()
{
register_setting(« wp_child_theme_options_page », « wp_child_theme_setting », « wct_callback »);
register_setting(« wp_child_theme_options_page », « wp_child_theme_setting_html », « wct_callback »);
}
add_action(« admin_init », « wp_child_theme_register_settings »);
function wp_child_theme_register_options_page()
{
add_options_page(« Child Theme Settings », « Child Theme », « manage_options », « wp_child_theme », « wp_child_theme_register_options_page_form »);
}
add_action(« admin_menu », « wp_child_theme_register_options_page »);
function wp_child_theme_register_options_page_form()
{
?>
<div id= »wp_child_theme »>
<h1>Child Theme Options</h1>
<h2>Include or Exclude Parent Theme Stylesheet</h2>
<form method= »post » action= »options.php »>
<?php settings_fields(« wp_child_theme_options_page »); ?>
<p><label><input size= »3″ type= »checkbox » name= »wp_child_theme_setting » id= »wp_child_theme_setting » <?php if((esc_attr(get_option(« wp_child_theme_setting »)) == « Yes »)) { echo » checked « ; } ?> value= »Yes »> Tick to disable the parent stylesheet<label></p>
<p><label><input size= »3″ type= »checkbox » name= »wp_child_theme_setting_html » id= »wp_child_theme_setting_html » <?php if((esc_attr(get_option(« wp_child_theme_setting_html »)) == « Yes »)) { echo » checked « ; } ?> value= »Yes »> Tick to disable the <a href= »https://uibmeta.org »>UIB Meta Tag</a> on your website homepage<label></p>
<?php submit_button(); ?>
</form>
</div>
<?php
}
// Offrir un jQuery plus moderne au besoin
/*
add_filter(‘wp_default_scripts’, function (&$scripts) {
if (!is_admin()) $scripts->remove(‘jquery’);
// On définit que le jquery.js du thème sera chargé en cas de besoin (rien n’est chargé sinon)
$scripts->add(‘jquery’, get_template_directory_uri() . ‘/scripts/jquery.js’, [], false);
});
*/
/**
* Nettoie une valeur insérée dans une page HTML
* Doit être utilisée à chaque insertion de données dynamique dans une page HTML
* Permet d’éviter les problèmes d’exécution de code indésirable (XSS)
* @param string $valeur Valeur à nettoyer
* @return string Valeur nettoyée
*/
function escape($valeur)
{
// Convertit les caractères spéciaux en entités HTML
return htmlspecialchars($valeur, ENT_QUOTES, ‘UTF-8’, false);
}
// ***************************************************
// Code pour exécuter un script PHP dans Elementor
// ***************************************************
// Nom du Shortcode de sortie pour inserer un code PHP dans Elementor
// Déclaration de la variable
function wpcode_elementor_shortcode( $atts ) {
/* fonction pour les tissus*/
$id = $_GET[‘id’];
$Description = $_GET[‘Description’];
$Prix = $_GET[‘Prix’];
escape($id) ;
escape($Description);
escape($Prix);
$foo = »;
if($id == NULL) {
$id = 15402;
$Description = ‘Tissu Velours’;
$Prix = 40;
}
echo « Bonjour, merci de votre visite ! »;
echo ‘<table style= »overflow: auto »>
<tbody>
<tr>
<td style= »overflow: auto »>’;
echo « <center><img class=’alignnone’ style=’witdh:1000px; height:300px;’ src= https://akramameublement.com/ameublement/?p=$id alt=’Tapissier Salons Marocains Canapés’ ></center> »;
echo'</td>
<td style= »overflow: auto; »>’;
echo « Ref : $id /2022 » ;
echo »<br> »;
echo « Description : $Description »;
echo »<br> »;
echo « Prix: $Prix Dh/m »;
echo'</td>
</tr>
</tbody>
</table>’ ;
}
add_shortcode( ‘elementor_php_sortie_1’, ‘wpcode_elementor_shortcode’);
function wpcode2_elementor_shortcode( $atts ) {
/* fonction pour les Salons*/
$id = $_GET[‘id’];
$Description = $_GET[‘Description’];
$Prix = $_GET[‘Prix’];
$Prix2 = $_GET[‘Prix2’];
escape($id) ;
escape($Description);
escape($Prix);
escape($Prix2);
if($id == NULL) {
$id = 15839;
$Description = ‘Salon Marocain Tissu Anti Tache’;
$Prix = ‘1600 ‘;
$Prix2 = ‘–‘ ;
}
echo « Bonjour, merci de votre visite ! »;
echo ‘<table style= »overflow: auto; »>
<tbody>
<tr>
<td style= »overflow: auto »>’;
echo « <center><img class=’alignnone’ style=’witdh: 1000px; height: 300px;’ src= https://akramameublement.com/ameublement/?p=$id alt=’Tapissier Salons Marocains Canapés’ ></center> »;
echo'</td>
<td style= »overflow: auto; »>’;
echo « Ref : $id /2022 » ;
echo »<br> »;
echo « Description : $Description »;
echo »<br> »;
echo « Prix sans Dossier: $Prix Dh/m »;
echo »<br> »;
echo « Prix avec Dossier: $Prix2 Dh/m »;
echo'</td>
</tr>
</tbody>
</table>’ ;
}
add_shortcode( ‘elementor_php_sortie_2’, ‘wpcode2_elementor_shortcode’);
function wpcode3_elementor_shortcode( $atts ) {
/* fonction pour les Sommiers*/
$id = $_GET[‘id’];
$id1 = $id;
$Description = $_GET[‘Description’];
$Prix = $_GET[‘Prix’];
$Prix2 = $_GET[‘Prix2’];
escape($id) ;
escape($Description);
escape($Prix);
escape($Prix2);
$id3=$id;
if ($id == NULL) {
$id = 15523;
$id1 = $id;
$Long = ‘190’;
$Larg = ‘140’;
$Description = ‘Sommier et tete de lit’;
$Prix = ‘1500’;
$Prix2 = ‘1400’;
}
echo « Bonjour, merci de votre visite ! »;
echo ‘<table style= »overflow: auto; »>
<tbody>
<tr>
<td style= »overflow: auto »>’;
echo « <center><img class=’alignnone’ style=’witdh: 300px; height: 217px;’ src= https://akramameublement.com/ameublement/?p=$id alt=’Tapissier Salons Marocains Canapés’ ></center> »;
echo'</td>
<td style= »overflow: auto; »>’;
echo « Ref : $id /2022 » ;
echo »<br> »;
echo « Description : $Description »;
echo »<br> »;
echo « Prix Sommier: $Prix Dh »;
echo »<br> »;
echo « Prix Tete de lit: $Prix2 Dh »;
echo »<br> »;
$Somme=($Prix+$Prix2)*0.95;
echo « Prix Sommier + Tete de lit: $Somme Dh »;
echo'</td>
</tr>
</tbody>
</table>’ ;
echo « NB: Les prix annoncés concernent les dimensions standards(190cm*140cm). »;
echo »<br> « ;
echo »<br> « ;
echo « Pour des dimensions superieurs : « ;
echo »<br> « ;
echo'<form action= »https://akramameublement.com/ameublement/ameublement-tapissier-tapisserie-voilage/?id=3530/ » method= »get »
class= »form-example »>
<div class= »form-example »>
<label for= »Long »>Enter la Longueur en cm :</label>
<input type= »number » name= »Long » id= »Long » required>’;
$Long = $_GET[« Long »];
echo’ </div>
<div class= »form-example »>
<label for= »Larg »>Entrer la largeur en cm :</label>
<input type= »number » name= »Larg » id= »Larg » required>’;
$Larg = $_GET[« Larg »];
echo’ </div>’;
echo’ </div>
<div class= »form-example »>
<input id= »prodId » name= »prodId » type= »hidden » value= »‘;
echo $id1 ;
echo ‘ » >’;
$prodId = $_GET[« prodId »];
echo’ </div>’;
echo’ </div>
<div class= »form-example »>
<input id= »Prix » name= »Prix » type= »hidden » value= »‘;
echo $Prix ;
echo ‘ » >’;
$Prix = $_GET[« Prix »];
echo’ </div>
<div class= »form-example »>
<input id= »Prix2″ name= »Prix2″ type= »hidden » value= »‘;
echo $Prix2 ;
echo ‘ » >’;
$Prix2 = $_GET[« Prix2 »];
echo’ </div>
<div class= »form-example »>
<input id= »Description » name= »Description » type= »hidden » value= »‘;
echo $Description ;
echo ‘ » >’;
$Description = $_GET[« Description »];
echo’ </div>’;
echo ‘ <div class= »form-example »>
<input type= »submit » value= »Validez! »>
</div>
</form> ‘;
}
add_shortcode( ‘elementor_php_sortie_3’, ‘wpcode3_elementor_shortcode’);
function wpcode4_elementor_shortcode( $atts ) {
/* fonction pour les Resultats Sommiers*/
$id = $_GET[‘prodId’];
$Description = $_GET[‘Description’];
$Prix = $_GET[‘Prix’];
$Prix2 = $_GET[‘Prix2’];
$Long = $_GET[‘Long’];
$Larg = $_GET[‘Larg’];
escape($id) ;
escape($Description);
escape($Prix);
escape($Prix2);
escape($Long);
escape($Larg);
if($id == NULL) {
$id = 15523;
$id1 =$id;
$Long = ‘190’;
$Larg = ‘140’;
$Description = ‘Sommier et tete de lit’;
$Prix = ‘1500’;
$Prix2 = ‘1400’;
}
$dim = ($Long*$Larg)/26600;
$dim=round($dim,2);
$Prix =($Prix)*$dim;
$Prix2 = ($Prix2)*$dim;
echo « Bonjour, merci de votre visite ! »;
echo ‘<table style= »overflow: auto; »>
<tbody>
<tr>
<td style= »overflow: auto « >’;
echo « <center><img class=’alignnone’ style=’witdh: 300px; height: 217px;’ src= https://akramameublement.com/ameublement/?p=$id alt=’Tapissier Salons Marocains Canapés’ ></center> »;
echo'</td>
<td style= »overflow: auto; »>’;
echo « Ref : $id /2022 » ;
echo »<br> »;
echo « Longueur : $Long cm »;
echo »<br> »;
echo « Largeur: $Larg cm »;
echo »<br> »;
echo « Prix Sommier: $Prix Dh »;
echo »<br> »;
echo « Prix Tete de lit: $Prix2 Dh »;
echo »<br> »;
$Somme =round(($Prix+$Prix2)*0.95,0);
echo « Prix Sommier + Tete de lit:$Somme Dh »;
echo'</td>
</tr>
</tbody>
</table>’ ;
}
add_shortcode( ‘elementor_php_sortie_4’, ‘wpcode4_elementor_shortcode’);
function wpcode5_elementor_shortcode( $atts ) {
/* fonction pour les Matelas */
$id = $_GET[‘id’];
$Description = $_GET[‘Description’];
$Prix = $_GET[‘Prix’];
escape($id) ;
escape($Description);
escape($Prix);
$id1=$id;
if($id == NULL) {
$id = 16066;
$id1=$id;
$Description = ‘Matelas Kinedorsal Dolidol’;
$Prix = ‘2750’;
}
echo « Bonjour, merci de votre visite ! »;
echo ‘<table style= »overflow: auto; »>
<tbody>
<tr>
<td style= »overflow: auto »>’;
echo « <center><img class=’alignnone’ style=’witdh: 1000px; height: 300px;’ src= https://akramameublement.com/ameublement/?p=$id alt=’Tapissier Salons Marocains Canapés’ ></center> »;
echo'</td>
<td style= »overflow: auto; »>’;
echo « Ref : $id /2022 » ;
echo »<br> »;
echo « Description : $Description »;
echo »<br> »;
echo « Prix : $Prix Dh »;
echo »<br> »;
echo'</td>
</tr>
</tbody>
</table>’ ;
echo « NB: Les prix annoncés concernent les dimensions standards(190cm*140cm). »;
echo »<br> « ;
echo »<br> « ;
echo « Pour des dimensions superieurs : « ;
echo »<br> « ;
echo »<br> « ;
echo »<br> « ;
echo'<form action= »https://akramameublement.com/ameublement/ResultatMatelas/?id=3530/ » method= »get »
class= »form-example »>
<div class= »form-example »>
<label for= »Long »>Enter la Longueur en cm :</label>
<input type= »number » name= »Long » id= »Long » required>’;
$Long = $_GET[« Long »];
echo’ </div>
<div class= »form-example »>
<label for= »Larg »>Entrer la largeur en cm :</label>
<input type= »number » name= »Larg » id= »Larg » required>’;
$Larg = $_GET[« Larg »];
echo’ </div>’;
echo’ </div>
<div class= »form-example »>
<input id= »prodId » name= »prodId » type= »hidden » value= »‘;
echo $id1 ;
echo ‘ » >’;
$prodId = $_GET[« prodId »];
echo’ </div>’;
echo’ </div>
<div class= »form-example »>
<input id= »Prix » name= »Prix » type= »hidden » value= »‘;
echo $Prix ;
echo ‘ » >’;
$Prix = $_GET[« Prix »];
echo’ </div>
<div class= »form-example »>
<input id= »Description » name= »Description » type= »hidden » value= »‘;
echo $Description ;
echo ‘ » >’;
$Description = $_GET[« Description »];
echo’ </div>’;
echo ‘ <div class= »form-example »>
<input type= »submit » value= »Validez! »>
</div>
</form> ‘;
}
add_shortcode( ‘elementor_php_sortie_5’, ‘wpcode5_elementor_shortcode’);
function wpcode6_elementor_shortcode( $atts ) {
/* fonction pour les Resultat Matelas*/
$id = $_GET[‘prodId’];
$Description = $_GET[‘Description’];
$Prix = $_GET[‘Prix’];
$Long = $_GET[‘Long’];
$Larg = $_GET[‘Larg’];
escape($id) ;
escape($Description);
escape($Prix);
escape($Long);
escape($Larg);
$dim = ($Long*$Larg)/26600;
$dim=round($dim,2);
$Prix =($Prix)*$dim;
if($id == NULL) {
$id = 16066;
$id1=$id;
$Description = ‘Matelas Kinedorsal Dolidol’;
$Prix = ‘2750’;
$Long = ‘190’;
$Larg = ‘140’;
}
echo « Bonjour, merci de votre visite ! »;
echo ‘<table style= »overflow: auto; »>
<tbody>
<tr>
<td style= »overflow: auto »>’;
echo « <center><img class=’alignnone’ style=’witdh: 1000px; height: 300px;’ src= https://akramameublement.com/ameublement/?p=$id alt=’Tapissier Salons Marocains Canapés’ ></center> »;
echo'</td>
<td style= »overflow: auto; »>’;
echo « Ref : $id /2022 » ;
echo »<br> »;
echo « Description : $Description » ;
echo »<br> »;
echo « Longueur : $Long cm »;
echo »<br> »;
echo « Largeur: $Larg cm »;
echo »<br> »;
echo « Prix : $Prix Dh »;
echo »<br> »;
echo'</td>
</tr>
</tbody>
</table>’ ;
}
add_shortcode( ‘elementor_php_sortie_6’, ‘wpcode6_elementor_shortcode’);
function wpcode7_elementor_shortcode( $atts ) {
/* fonction pour Produit les Banquettes */
$id = $_GET[‘id’];
$id1 = $id ;
$Description = $_GET[‘Description’];
$Prix = $_GET[‘Prix’];
escape($id) ;
escape($Description);
escape($Prix);
$id3=$id;
if($id == NULL) {
$id = 15999;
$Description = ‘Banquette Ressort Kinedorsal Dolidol’;
$Prix = ‘700’;
$Larg = ’70’;
$Epaiss = ’26’;
}
echo « Bonjour, merci de votre visite ! »;
echo ‘<table style= »overflow: auto; »>
<tbody>
<tr>
<td style= »overflow: auto »>’;
echo « <center><img class=’alignnone’ style=’witdh: 1000px; height: 300px;’ src= https://akramameublement.com/ameublement/?p=$id alt=’Tapissier Salons Marocains Canapés’ ></center> »;
echo'</td>
<td style= »overflow: auto; »>’;
echo « Ref : $id /2022 » ;
echo »<br> »;
echo « Description : $Description » ;
echo »<br> »;
echo « Largeur: 70 cm »;
echo »<br> »;
echo « Epaisseur: 26/28 cm »;
echo »<br> »;
echo « Prix : $Prix Dh/m »;
echo »<br> »;
echo'</td>
</tr>
</tbody>
</table>’ ;
echo « NB: Les prix annoncés concernent les dimensions standards(100cm*70cm*26/28cm). »;
echo »<br> « ;
echo »<br> « ;
echo « Pour des dimensions superieures, Veuillez nous contacter en replissant le formulaire de contact mit a votre disposition. « ;
echo »<br> « ;
echo'<form action= »https://akramameublement.com/ameublement/ResultatRessort/?id=3530/ » method= »get »
class= »form-example »>
<div class= »form-example »>
<label for= »Long »>Enter la Largeur en cm :</label>
<input type= »number » name= »Larg » id= »Larg » required>’;
$Larg = $_GET[« Larg »];
echo’ </div>
<div class= »form-example »>
<label for= »Larg »>Entrer Epaisseur en cm :</label>
<input type= »number » name= »Epaiss » id= »Epaiss » required>’;
$Epaiss = $_GET[« Epaiss »];
echo’ </div>’;
echo’ </div>
<div class= »form-example »>
<input id= »prodId » name= »prodId » type= »hidden » value= »‘;
echo $id1 ;
echo ‘ » >’;
$prodId = $_GET[« prodId »];
echo’ </div>’;
echo’ </div>
<div class= »form-example »>
<input id= »Prix » name= »Prix » type= »hidden » value= »‘;
echo $Prix ;
echo ‘ » >’;
$Prix = $_GET[« Prix »];
echo’ </div>
<div class= »form-example »>
<input id= »Description » name= »Description » type= »hidden » value= »‘;
echo $Description ;
echo ‘ » >’;
$Description = $_GET[« Description »];
echo’ </div>’;
echo ‘ <div class= »form-example »>
<input type= »submit » value= »Validez! »>
</div>
</form> ‘;
echo »<br> « ;
echo »<br> « ;
}
add_shortcode( ‘elementor_php_sortie_7’, ‘wpcode7_elementor_shortcode’);
function wpcode8_elementor_shortcode( $atts ) {
/* fonction pour les Resultat Banquettes */
$id = $_GET[‘prodId’];
$Description = $_GET[‘Description’];
$Prix = $_GET[‘Prix’];
$Epaiss = $_GET[‘Epaiss’];
$Larg = $_GET[‘Larg’];
escape($id) ;
escape($Description);
escape($Prix);
escape($Epaiss);
escape($Larg);
$dim = ($Epaiss*$Larg)/1820;
$dim=round($dim,2);
$Prix =($Prix)*$dim;
if($id == NULL) {
$id = 15999;
$Description = ‘Banquette Ressort Kinedorsal Dolidol’;
$Prix = ‘700’;
$Larg = ’70’;
$Epaiss = ’26’;
}
echo « Bonjour, merci de votre visite ! »;
echo ‘<table style= »overflow: auto; »>
<tbody>
<tr>
<td style= »overflow: auto »>’;
echo « <center><img class=’alignnone’ style=’witdh: 1000px; height: 300px;’ src= https://akramameublement.com/ameublement/?p=$id alt=’Tapissier Salons Marocains Canapés’ ></center> »;
echo'</td>
<td style= »overflow: auto; »>’;
echo « Ref : $id /2022 » ;
echo »<br> »;
echo « Description : $Description » ;
echo »<br> »;
echo « Largeur : $Larg cm »;
echo »<br> »;
echo « Epaisseur: $Epaiss cm »;
echo »<br> »;
echo « Prix : $Prix Dh/m »;
echo »<br> »;
echo'</td>
</tr>
</tbody>
</table>’ ;
}
add_shortcode( ‘elementor_php_sortie_8’, ‘wpcode8_elementor_shortcode’);
function wpcode9_elementor_shortcode( $atts ) {
echo ‘
<form id= »formcontact » action= »http://localhost/ameublement/ » method= »post »>
<div class= »elem-group »>
<label for= »name »>Votre Nom</label>
<input type= »text » id= »name » name= »name_client » placeholder= »Ali Baba » pattern=[A-Z\sa-z]{3,20} required>
</div>
<div class= »elem-group »>
<label class= »remark »>Remark</label>
<input class= »remark » name= »remark »
pattern= »[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$ »
placeholder= »name@domain.com »>
</div>
<div class= »elem-group »>
<label for= »email »>Votre E-mail</label>
<input type= »email » id= »email » name= »email_client » placeholder= »aliBaba@email.com » required>
</div>
<div class= »elem-group »>
<label for= »department-selection »>Votre Pays</label>
<select id= »department-selection » name= »pays » required>
<option value= »Maroc »>Maroc</option>
<option value= »France »>France</option>
<option value= »Italie »>Italie</option>
<option value= »Autres Pays »>autres Pays</option>
</select>
</div>
<div class= »elem-group »>
<label for= »title »>Objet</label>
<input type= »text » id= »title » name= »objet_email » required placeholder= »Demande Devis » pattern=[A-Za-z0-9\s]{6,60}>
</div>
<div class= »elem-group »>
<label for= »message »>Votre message</label>
<textarea id= »message » name= »message_client » placeholder= »Ecrire votre message ici. » required></textarea>
</div>
<button type= »submit »>Validez Message</button>
</form>’;
}
add_shortcode( ‘elementor_php_sortie_9’, ‘wpcode9_elementor_shortcode’);
function wpcode10_elementor_shortcode( $atts ) {
// fonction pour Confirmation
$remark = $_GET[‘remark’];
$message_client = $_GET[‘message_client’];
$name_client = $_GET[‘name_client’];
$email_client = $_GET[’email_client’];
$email_title = $_GET[‘objet_email’];
$pays = $_GET[‘pays’];
if ($_POST[‘remark’] != « ») { die(); }
if($_POST) {
$name_client = « »;
$email_client = « »;
$objet_email = « »;
$pays = « »;
$message_client = « »;
$email_body = « <div> »;
if(isset($_POST[‘name_client’])) {
$name_client = filter_var($_POST[‘name_client’], FILTER_SANITIZE_STRING);
$email_body .= « <div>
<label><b>Nom:</b></label> <span> ».$name_client. »</span>
</div> »;
}
if(isset($_POST[’email_client’])) {
$email_client = str_replace(array(« \r », « \n », « %0a », « %0d »), », $_POST[’email_client’]);
$email_client = filter_var($email_clientl, FILTER_VALIDATE_EMAIL);
$email_body .= « <div>
<label><b>Email:</b></label> <span> ».$email_client. »</span>
</div> »;
}
if(isset($_POST[‘objet_email’])) {
$objet_email = filter_var($_POST[‘objet_email’], FILTER_SANITIZE_STRING);
$email_body .= « <div>
<label><b>Objet:</b></label> <span> ».$objet_email. »</span>
</div> »;
}
if(isset($_POST[‘pays’])) {
$pays = filter_var($_POST[‘pays’], FILTER_SANITIZE_STRING);
$email_body .= « <div>
<label><b>Pays:</b></label> <span> ».$pays. »</span>
</div> »;
}
if(isset($_POST[‘message_client’])) {
$message_client = htmlspecialchars($_POST[‘message_client’]);
$email_body .= « <div>
<label><b>Message:</b></label>
<div> ».$message_client. »</div>
</div> »;
}
if($pays == « billing ») {
$recipient = « billing@domain.com »;
}
else if($pays == « marketing ») {
$recipient = « marketing@domain.com »;
}
else if($pays == « technical support ») {
$recipient = « tech.support@domain.com »;
}
else {
$recipient = « akramameublement@gmail.com »;
}
$email_body .= « </div> »;
$headers = ‘MIME-Version: 1.0’ . « \r\n »
.’Content-type: text/html; charset=utf-8′ . « \r\n »
.’From: ‘ . $email_client . « \r\n »;
if(mail($recipient, $objet_email, $email_body, $headers)) {
// echo » <p>Merci de nous avoir contacter Mer/Meme $visitor_name. Nous vous repondrons dans moins de 24 heures.</p> »;
// header(‘Location:contact2.php’);
// exit;
} else {
echo ‘<p>desole, nous ne pouvons pas recevoir votre message, utilisez notre Email : akramameublement.com ou notre Whattsap : 212 661245588.</p>’;
}
} else {
echo ‘<p></p>’;
}
}
add_shortcode( ‘elementor_php_sortie_10’, ‘wpcode10_elementor_shortcode’);
function tpz_display_page_title( $display = true )
{
$m = get_query_var( ‘m’ );
$year = get_query_var( ‘year’ );
$monthnum = get_query_var( ‘monthnum’ );
$day = get_query_var( ‘day’ );
$search = get_query_var( ‘s’ );
$title = »;
// If there is a post
if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) )
{
$title = single_post_title( », false );
}
// If there’s a post type archive
if ( is_post_type_archive() )
{
$post_type = get_query_var( ‘post_type’ );
if ( is_array( $post_type ) )
{
$post_type = reset( $post_type );
}
$post_type_object = get_post_type_object( $post_type );
if ( ! $post_type_object->has_archive )
{
$title = post_type_archive_title( », false );
}
}
// If there’s a category or tag
if ( is_category() || is_tag() )
{
$title = single_term_title( », false );
}
// If there’s a taxonomy
if ( is_tax() )
{
$term = get_queried_object();
if ( $term )
{
$tax = get_taxonomy( $term->taxonomy );
$title = single_term_title( $tax->labels->name, false );
}
}
// If there’s an author
if ( is_author() && ! is_post_type_archive() )
{
$author = get_queried_object();
if ( $author )
{
$title = $author->display_name;
}
}
// Post type archives with has_archive should override terms.
if ( is_post_type_archive() && $post_type_object->has_archive )
{
$title = post_type_archive_title( », false );
}
// If there’s a month
if ( is_archive() && ! empty( $m ) )
{
$my_year = substr( $m, 0, 4 );
$my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
$my_day = intval( substr( $m, 6, 2 ) );
$title = $my_year . ( $my_month ? $my_month : » ) . ( $my_day ? $my_day : » );
}
// If there’s a year
if ( is_archive() && ! empty( $year ) )
{
$title = $year;
if ( ! empty( $monthnum ) )
{
$title .= $wp_locale->get_month( $monthnum );
}
if ( ! empty( $day ) )
{
$title .= zeroise( $day, 2 );
}
}
// If it’s a search
if ( is_search() )
{
// translators: 1: separator, 2: search phrase
$title = sprintf( __( ‘Résultats de la recherche pour : %s’ ), strip_tags( $search ) );
}
// If it’s a 404 page
if ( is_404() )
{
$title = __( ‘Erreur 404, la page est introuvable’ );
}
// Send it out
if ( $display )
{
echo $title;
}
else
{
$title = « <h1>$title </h1> »;
return $title ;
}
$title = tpz_display_page_title(false);
}
add_shortcode( ‘elementor_php_sortie_11’, ‘tpz_display_page_title’);
// ce qui suit nettoie les lignes unutiles ajoutees par wp dans le header: anc code JS
function nettoie_head_scripts() {
automatic_feed_links(false);
remove_action(‘wp_head’, ‘wp_generator’);
remove_action(‘wp_head’, ‘wp_shortlink_wp_head’, 10, 0 );
remove_action(‘wp_head’, ‘wp_dlmp_l10n_style’ );
remove_action(‘wp_head’, ‘rsd_link’);
remove_action(‘wp_head’, ‘wlwmanifest_link’);
}
add_action( ‘wp_enqueue_scripts’, ‘nettoie_head_scripts’ );
// Script pour déplacer les JS dans le footer
function remove_head_scripts() {
remove_action(‘wp_head’, ‘wp_print_scripts’);
remove_action(‘wp_head’, ‘wp_print_head_scripts’, 9);
remove_action(‘wp_head’, ‘wp_enqueue_scripts’, 1);
add_action(‘wp_footer’, ‘wp_print_scripts’, 5);
add_action(‘wp_footer’, ‘wp_enqueue_scripts’, 5);
add_action(‘wp_footer’, ‘wp_print_head_scripts’, 5);
}
//** *Activer Ajout Images WebP.*/
function webp_upload_mimes($existing_mimes) {
$existing_mimes[‘webp’] = ‘image/webp’;
return $existing_mimes;
}
add_filter(‘mime_types’, ‘webp_upload_mimes’);
//** * Activer Apercu Images WebP.*/
function webp_is_displayable($result, $path) {
if ($result === false) {
$displayable_image_types = array( IMAGETYPE_WEBP );
$info = @getimagesize( $path );
if (empty($info)) {
$result = false;
} elseif (!in_array($info[2], $displayable_image_types)) {
$result = false;
} else {
$result = true;
}
}
return $result;
}
add_filter(‘file_is_displayable_image’, ‘webp_is_displayable’, 10, 2);
function afficher_produits_shortcode() {
global $wpdb;
$table_produits = ‘produits’;
$resultats = $wpdb->get_results(« SELECT * FROM $table_produits »);
if (empty($resultats)) {
return ‘<p>Aucun produit trouvé.</p>’;
}
// Début HTML + CSS + JavaScript
$output = ‘
<style>
.liste-produits {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 20px;
}
.produit {
border: 1px solid #ccc;
padding: 15px;
border-radius: 10px;
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
background: #fff;
transition: transform 0.3s ease;
box-sizing: border-box;
}
.produit:hover {
transform: scale(1.02);
}
.produit img {
max-width: 100%;
height: auto;
border-radius: 6px;
}
.produit h3 {
margin: 10px 0 5px;
font-size: 18px;
}
.produit p {
font-size: 14px;
color: #555;
}
.produit strong {
color: green;
font-size: 16px;
}
.pagination-btns {
margin-top: 20px;
text-align: center;
}
.pagination-btns button {
background-color: #0073aa;
color: #fff;
border: none;
padding: 10px 20px;
margin: 0 10px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
}
.pagination-btns button:hover {
background-color: #005d8d;
}
@media (max-width: 768px) {
.liste-produits {
grid-template-columns: 1fr;
}
}
</style>
<div class= »liste-produits »>’;
// Ajouter chaque produit avec une classe spéciale pour la pagination JS
$i = 0;
foreach ($resultats as $produit) {
$image_src = $produit->image_url
? $produit->image_url
: wp_upload_dir()[‘baseurl’] . ‘/’ . $produit->image_produit;
$output .= ‘
<div class= »produit produit-item » data-index= »‘ . $i . ‘ » style= »display: none; »>
<img src= »‘ . esc_url($image_src) . ‘ » alt= »‘ . esc_attr($produit->nom_produit) . ‘ »>
<h3>’ . esc_html($produit->nom_produit) . ‘</h3>
<p>’ . esc_html($produit->description) . ‘</p>
<strong>’ . esc_html($produit->prix) . ‘ MAD</strong>
</div>’;
$i++;
}
$output .= ‘</div>
<div class= »pagination-btns »>
<button id= »afficher-moins » style= »display:none; »>Afficher Moins</button>
<button id= »afficher-plus »>Afficher Plus</button>
</div>
<script>
(function() {
const produits = document.querySelectorAll(« .produit-item »);
const btnPlus = document.getElementById(« afficher-plus »);
const btnMoins = document.getElementById(« afficher-moins »);
const produitsParPage = 8; // 2 lignes (4 x 2)
let visible = produitsParPage;
function afficherProduits() {
produits.forEach((el, i) => {
el.style.display = i < visible ? « block » : « none »;
});
btnMoins.style.display = visible > produitsParPage ? « inline-block » : « none »;
btnPlus.style.display = visible < produits.length ? « inline-block » : « none »;
}
btnPlus.addEventListener(« click », () => {
visible += produitsParPage;
afficherProduits();
});
btnMoins.addEventListener(« click », () => {
visible -= produitsParPage;
if (visible < produitsParPage) visible = produitsParPage;
afficherProduits();
});
afficherProduits(); // au chargement
})();
</script>
‘;
return $output;
}
add_shortcode(‘afficher_produits’, ‘afficher_produits_shortcode’);
function afficher_produits2_shortcode() {
global $wpdb;
$table_produits = ‘produits’;
// ✅ On sélectionne seulement les produits de catégorie 104 triés par ordreAffichage
$resultats = $wpdb->get_results(«
SELECT * FROM $table_produits
WHERE categorie = 102
ORDER BY ordreAffichage ASC
« );
if (empty($resultats)) {
return ‘<p>Aucun produit trouvé.</p>’;
}
// Début HTML + CSS + JavaScript
$output = ‘
<style>
.liste-produits {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 20px;
}
.produit {
border: 1px solid #ccc;
padding: 15px;
border-radius: 10px;
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
background: #fff;
transition: transform 0.3s ease;
box-sizing: border-box;
}
.produit:hover {
transform: scale(1.02);
}
.produit img {
max-width: 100%;
height: auto;
border-radius: 6px;
}
.produit h3 {
margin: 10px 0 5px;
font-size: 18px;
}
.produit p {
font-size: 14px;
color: #555;
}
.produit strong {
color: green;
font-size: 16px;
}
.pagination-btns {
margin-top: 20px;
text-align: center;
}
.pagination-btns button {
background-color: #0073aa;
color: #fff;
border: none;
padding: 10px 20px;
margin: 0 10px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
}
.pagination-btns button:hover {
background-color: #005d8d;
}
@media (max-width: 768px) {
.liste-produits {
grid-template-columns: 1fr;
}
}
</style>
<div class= »liste-produits »>’;
// Ajouter chaque produit avec une classe spéciale pour la pagination JS
$i = 0;
foreach ($resultats as $produit) {
$image_src = $produit->image_url
? $produit->image_url
: wp_upload_dir()[‘baseurl’] . ‘/’ . $produit->image_produit;
$output .= ‘
<div class= »produit produit-item » data-index= »‘ . $i . ‘ » style= »display: none; »>
<a href= »‘ . site_url(‘/?page_id=481&id=’ . $produit->id) . ‘ »>
<img src= »‘ . esc_url($image_src) . ‘ » alt= »‘ . esc_attr($produit->nom_produit) . ‘ »>
</a>
<h3>’ . esc_html($produit->nom_produit) . ‘</h3>
<p>’ . esc_html($produit->description) . ‘</p>
<strong>’ . esc_html($produit->prix) . ‘ MAD</strong>
</div>’;
$i++;
}
$output .= ‘</div>
<div class= »pagination-btns »>
<button id= »afficher-moins » style= »display:none; »>Afficher Moins</button>
<button id= »afficher-plus »>Afficher Plus</button>
</div>
<script>
(function() {
const produits = document.querySelectorAll(« .produit-item »);
const btnPlus = document.getElementById(« afficher-plus »);
const btnMoins = document.getElementById(« afficher-moins »);
const produitsParPage = 8; // 2 lignes (4 x 2)
let visible = produitsParPage;
function afficherProduits() {
produits.forEach((el, i) => {
el.style.display = i < visible ? « block » : « none »;
});
btnMoins.style.display = visible > produitsParPage ? « inline-block » : « none »;
btnPlus.style.display = visible < produits.length ? « inline-block » : « none »;
}
btnPlus.addEventListener(« click », () => {
visible += produitsParPage;
afficherProduits();
});
btnMoins.addEventListener(« click », () => {
visible -= produitsParPage;
if (visible < produitsParPage) visible = produitsParPage;
afficherProduits();
});
afficherProduits(); // au chargement
})();
</script>
‘;
return $output;
}
add_shortcode(‘afficher_produits2’, ‘afficher_produits2_shortcode’);
function afficher_produit_detail_shortcode() {
global $wpdb;
// On récupère l’ID via $_GET[‘id’]
$id = isset($_GET[‘id’]) ? intval($_GET[‘id’]) : 0;
if ($id <= 0) {
return ‘<p>Produit introuvable (ID manquant ou invalide).</p>’;
}
// ⚠️ Nom exact de la table sans préfixe
$table_produits = ‘produits’;
// Requête préparée
$produit = $wpdb->get_row(
$wpdb->prepare(« SELECT * FROM $table_produits WHERE id = %d », $id)
);
if (!$produit) {
return ‘<p>Produit introuvable (aucun produit avec ID ‘ . esc_html($id) . ‘).</p>’;
}
$image_src = $produit->image_url
? $produit->image_url
: wp_upload_dir()[‘baseurl’] . ‘/’ . $produit->image_produit;
$output = ‘
<div class= »produit-detail » style= »max-width: 800px; margin: auto; padding: 20px; »>
<img src= »‘ . esc_url($image_src) . ‘ » style= »max-width:100%; border-radius:10px; » />
<h2>’ . esc_html($produit->nom_produit) . ‘</h2>
<p><strong>Prix :</strong> ‘ . esc_html($produit->prix) . ‘ MAD</p>
<p><strong>Description :</strong><br>’ . esc_html($produit->description) . ‘</p>
</div>’;
return $output;
}
add_shortcode(‘afficher_produit_detail’, ‘afficher_produit_detail_shortcode’);
function afficher_produits3_shortcode() {
global $wpdb;
$table_produits = ‘produits’;
// ✅ On sélectionne seulement les produits de catégorie 104 triés par ordreAffichage
$resultats = $wpdb->get_results(«
SELECT * FROM $table_produits
WHERE categorie = 103
ORDER BY ordreAffichage ASC
« );
if (empty($resultats)) {
return ‘<p>Aucun produit trouvé.</p>’;
}
// Début HTML + CSS + JavaScript
$output = ‘
<style>
.liste-produits {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 20px;
}
.produit {
border: 1px solid #ccc;
padding: 15px;
border-radius: 10px;
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
background: #fff;
transition: transform 0.3s ease;
box-sizing: border-box;
}
.produit:hover {
transform: scale(1.02);
}
.produit img {
max-width: 100%;
height: auto;
border-radius: 6px;
}
.produit h3 {
margin: 10px 0 5px;
font-size: 18px;
}
.produit p {
font-size: 14px;
color: #555;
}
.produit strong {
color: green;
font-size: 16px;
}
.pagination-btns {
margin-top: 20px;
text-align: center;
}
.pagination-btns button {
background-color: #0073aa;
color: #fff;
border: none;
padding: 10px 20px;
margin: 0 10px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
}
.pagination-btns button:hover {
background-color: #005d8d;
}
@media (max-width: 768px) {
.liste-produits {
grid-template-columns: 1fr;
}
}
</style>
<div class= »liste-produits »>’;
// Ajouter chaque produit avec une classe spéciale pour la pagination JS
$i = 0;
foreach ($resultats as $produit) {
$image_src = $produit->image_url
? $produit->image_url
: wp_upload_dir()[‘baseurl’] . ‘/’ . $produit->image_produit;
$output .= ‘
<div class= »produit produit-item » data-index= »‘ . $i . ‘ » style= »display: none; »>
<a href= »‘ . site_url(‘/?page_id=481&id=’ . $produit->id) . ‘ »>
<img src= »‘ . esc_url($image_src) . ‘ » alt= »‘ . esc_attr($produit->nom_produit) . ‘ »>
</a>
<h3>’ . esc_html($produit->nom_produit) . ‘</h3>
<p>’ . esc_html($produit->description) . ‘</p>
<strong>’ . esc_html($produit->prix) . ‘ MAD</strong>
</div>’;
$i++;
}
$output .= ‘</div>
<div class= »pagination-btns »>
<button id= »afficher-moins » style= »display:none; »>Afficher Moins</button>
<button id= »afficher-plus »>Afficher Plus</button>
</div>
<script>
(function() {
const produits = document.querySelectorAll(« .produit-item »);
const btnPlus = document.getElementById(« afficher-plus »);
const btnMoins = document.getElementById(« afficher-moins »);
const produitsParPage = 8; // 2 lignes (4 x 2)
let visible = produitsParPage;
function afficherProduits() {
produits.forEach((el, i) => {
el.style.display = i < visible ? « block » : « none »;
});
btnMoins.style.display = visible > produitsParPage ? « inline-block » : « none »;
btnPlus.style.display = visible < produits.length ? « inline-block » : « none »;
}
btnPlus.addEventListener(« click », () => {
visible += produitsParPage;
afficherProduits();
});
btnMoins.addEventListener(« click », () => {
visible -= produitsParPage;
if (visible < produitsParPage) visible = produitsParPage;
afficherProduits();
});
afficherProduits(); // au chargement
})();
</script>
‘;
return $output;
}
add_shortcode(‘afficher_produits3’, ‘afficher_produits3_shortcode’);
function afficher_produits4_shortcode() {
global $wpdb;
$table_produits = ‘produits’;
// ✅ On sélectionne seulement les produits de catégorie 104 triés par ordreAffichage
$resultats = $wpdb->get_results(«
SELECT * FROM $table_produits
WHERE categorie = 104
ORDER BY ordreAffichage ASC
« );
if (empty($resultats)) {
return ‘<p>Aucun produit trouvé.</p>’;
}
// Début HTML + CSS + JavaScript
$output = ‘
<style>
.liste-produits {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 20px;
}
.produit {
border: 1px solid #ccc;
padding: 15px;
border-radius: 10px;
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
background: #fff;
transition: transform 0.3s ease;
box-sizing: border-box;
}
.produit:hover {
transform: scale(1.02);
}
.produit img {
max-width: 100%;
height: auto;
border-radius: 6px;
}
.produit h3 {
margin: 10px 0 5px;
font-size: 18px;
}
.produit p {
font-size: 14px;
color: #555;
}
.produit strong {
color: green;
font-size: 16px;
}
.pagination-btns {
margin-top: 20px;
text-align: center;
}
.pagination-btns button {
background-color: #0073aa;
color: #fff;
border: none;
padding: 10px 20px;
margin: 0 10px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
}
.pagination-btns button:hover {
background-color: #005d8d;
}
@media (max-width: 768px) {
.liste-produits {
grid-template-columns: 1fr;
}
}
</style>
<div class= »liste-produits »>’;
// Ajouter chaque produit avec une classe spéciale pour la pagination JS
$i = 0;
foreach ($resultats as $produit) {
$image_src = $produit->image_url
? $produit->image_url
: wp_upload_dir()[‘baseurl’] . ‘/’ . $produit->image_produit;
$output .= ‘
<div class= »produit produit-item » data-index= »‘ . $i . ‘ » style= »display: none; »>
<a href= »‘ . site_url(‘/?page_id=481&id=’ . $produit->id) . ‘ »>
<img src= »‘ . esc_url($image_src) . ‘ » alt= »‘ . esc_attr($produit->nom_produit) . ‘ »>
</a>
<h3>’ . esc_html($produit->nom_produit) . ‘</h3>
<p>’ . esc_html($produit->description) . ‘</p>
<strong>’ . esc_html($produit->prix) . ‘ MAD</strong>
</div>’;
$i++;
}
$output .= ‘</div>
<div class= »pagination-btns »>
<button id= »afficher-moins » style= »display:none; »>Afficher Moins</button>
<button id= »afficher-plus »>Afficher Plus</button>
</div>
<script>
(function() {
const produits = document.querySelectorAll(« .produit-item »);
const btnPlus = document.getElementById(« afficher-plus »);
const btnMoins = document.getElementById(« afficher-moins »);
const produitsParPage = 8; // 2 lignes (4 x 2)
let visible = produitsParPage;
function afficherProduits() {
produits.forEach((el, i) => {
el.style.display = i < visible ? « block » : « none »;
});
btnMoins.style.display = visible > produitsParPage ? « inline-block » : « none »;
btnPlus.style.display = visible < produits.length ? « inline-block » : « none »;
}
btnPlus.addEventListener(« click », () => {
visible += produitsParPage;
afficherProduits();
});
btnMoins.addEventListener(« click », () => {
visible -= produitsParPage;
if (visible < produitsParPage) visible = produitsParPage;
afficherProduits();
});
afficherProduits(); // au chargement
})();
</script>
‘;
return $output;
}
add_shortcode(‘afficher_produits4’, ‘afficher_produits4_shortcode’);
function afficher_produits_par_nom_page() {
global $wpdb;
$nom_page = get_the_title(); // Le nom de la page WordPress
$categorie = $wpdb->get_row(
$wpdb->prepare(« SELECT * FROM categories WHERE nom_categorie = %s », $nom_page)
);
if (!$categorie) {
return « <p>Aucune catégorie trouvée pour : $nom_page</p> »;
}
// ✅ Récupérer les produits triés par ordreAffichage croissant
$produits = $wpdb->get_results(
$wpdb->prepare(« SELECT * FROM produits WHERE categorie = %d ORDER BY ordreAffichage ASC », $categorie->id)
);
if (empty($produits)) {
return « <p>Aucun produit trouvé dans cette catégorie.</p> »;
}
ob_start();
?>
<style>
.liste-produits {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20px;
margin-bottom: 20px;
}
.produit {
border: 1px solid #ccc;
padding: 15px;
border-radius: 10px;
text-align: center;
background-color: #fff;
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
}
.produit:hover {
transform: scale(1.02);
}
.produit img {
max-width: 100%;
height: auto;
border-radius: 6px;
}
.pagination-btns {
text-align: center;
margin-top: 20px;
}
.pagination-btns button {
background-color: #0073aa;
color: white;
border: none;
padding: 10px 20px;
margin: 0 10px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
}
.pagination-btns button:hover {
background-color: #005d8d;
}
@media (max-width: 768px) {
.liste-produits {
grid-template-columns: 1fr;
}
}
</style>
<div class= »liste-produits »>
<?php
$i = 0;
foreach ($produits as $produit) {
$image = »;
if (!empty($produit->image_url)) {
$image = esc_url($produit->image_url);
} elseif (!empty($produit->image_produit)) {
$image = esc_url(wp_upload_dir()[‘baseurl’] . ‘/’ . ltrim($produit->image_produit, ‘/’));
}
$nom = esc_html($produit->nom_produit);
$prix = esc_html($produit->prix);
$url_detail = site_url(‘/?page_id=481&id=’ . $produit->id); // Tu peux remplacer 481 par l’ID de ta page produit
echo «
<div class=’produit produit-item’ data-index=’$i’ style=’display: none;’>
<a href=’$url_detail’>
<img src=’$image’ alt=’$nom’ width=’200′>
</a>
<h3>$nom</h3>
<p><strong>Prix :</strong> $prix MAD</p>
</div> »;
$i++;
}
?>
</div>
<div class= »pagination-btns »>
<button id= »afficher-moins » style= »display:none; »>Afficher Moins</button>
<button id= »afficher-plus »>Afficher Plus</button>
</div>
<script>
(function() {
const produits = document.querySelectorAll(« .produit-item »);
const btnPlus = document.getElementById(« afficher-plus »);
const btnMoins = document.getElementById(« afficher-moins »);
const produitsParPage = 16;
let visible = produitsParPage;
function afficherProduits() {
produits.forEach((el, i) => {
el.style.display = i < visible ? « block » : « none »;
});
btnMoins.style.display = visible > produitsParPage ? « inline-block » : « none »;
btnPlus.style.display = visible < produits.length ? « inline-block » : « none »;
}
btnPlus.addEventListener(« click », () => {
visible += produitsParPage;
afficherProduits();
});
btnMoins.addEventListener(« click », () => {
visible -= produitsParPage;
if (visible < produitsParPage) visible = produitsParPage;
afficherProduits();
});
afficherProduits();
})();
</script>
<?php
return ob_get_clean();
}
add_shortcode(‘afficher_produits_par_page’, ‘afficher_produits_par_nom_page’);
function afficher_details_produit() {
global $wpdb;
if (!isset($_GET[‘id’])) {
return « <p>Aucun produit sélectionné.</p> »;
}
$id = intval($_GET[‘id’]);
$produit = $wpdb->get_row(
$wpdb->prepare(« SELECT * FROM produits WHERE id = %d », $id)
);
if (!$produit) {
return « <p>Produit introuvable.</p> »;
}
// 🔄 Gestion des images
$image_src = »;
if (!empty($produit->image_url)) {
$image_src = $produit->image_url;
} elseif (!empty($produit->image_produit)) {
$image_src = wp_upload_dir()[‘baseurl’] . ‘/’ . ltrim($produit->image_produit, ‘/’);
}
ob_start();
?>
<style>
.detail-produit {
display: flex;
flex-wrap: wrap;
gap: 30px;
padding: 20px;
border: 1px solid #ddd;
border-radius: 10px;
background-color: #f9f9f9;
}
.detail-produit img {
max-width: 400px;
border-radius: 10px;
}
.infos-produit {
flex: 1;
min-width: 300px;
}
.infos-produit h2 {
margin-top: 0;
color: #0073aa;
}
.infos-produit p {
margin: 5px 0;
font-size: 16px;
}
.infos-produit strong {
color: #333;
}
.description-details {
margin-top: 30px;
font-size: 15px;
line-height: 1.6;
padding: 15px;
background: #fff;
border: 1px solid #ccc;
border-radius: 8px;
}
</style>
<div class= »detail-produit »>
<?php if (!empty($image_src)): ?>
<div class= »image-produit »>
<img src= »<?php echo esc_url($image_src); ?> » alt= »<?php echo esc_attr($produit->nom_produit); ?> »>
</div>
<?php endif; ?>
<div class= »infos-produit »>
<h2><?php echo esc_html($produit->nom_produit); ?></h2>
<p><strong>Prix :</strong> <?php echo esc_html($produit->prix); ?> MAD</p>
<p><strong>En promotion :</strong> <?php echo $produit->en_promotion ? ‘Oui’ : ‘Non’; ?></p>
<p><strong>Remise :</strong> <?php echo esc_html($produit->remise); ?> %</p>
<p><strong>Date limite promotion :</strong> <?php echo esc_html($produit->date_limit_promotion); ?></p>
<p><strong>Description :</strong> <?php echo esc_html($produit->description); ?></p>
</div>
</div>
<div class= »description-details »>
<strong>Description détaillée :</strong><br>
<?php echo nl2br(esc_html($produit->description_details)); ?>
</div>
<?php
return ob_get_clean();
}
add_shortcode(‘afficher_details_produit’, ‘afficher_details_produit’);
function afficher_produits_par_categorie_shortcode($atts) {
global $wpdb;
$atts = shortcode_atts([
‘categorie’ => 0,
], $atts);
$categorie_id = intval($atts[‘categorie’]);
if ($categorie_id <= 0) {
return « <p>Aucune catégorie valide spécifiée.</p> »;
}
$produits = $wpdb->get_results(
$wpdb->prepare(« SELECT * FROM produits WHERE categorie = %d ORDER BY ordreAffichage ASC », $categorie_id)
);
if (empty($produits)) {
return « <p>Aucun produit trouvé pour cette catégorie.</p> »;
}
ob_start();
?>
<style>
.liste-produits {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20px;
margin-bottom: 20px;
}
.produit {
border: 1px solid #ccc;
padding: 15px;
border-radius: 10px;
text-align: center;
background-color: #fff;
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
}
.produit:hover {
transform: scale(1.02);
}
.produit img {
max-width: 100%;
height: auto;
border-radius: 6px;
}
.pagination-btns {
text-align: center;
margin-top: 20px;
}
.pagination-btns button {
background-color: #0073aa;
color: white;
border: none;
padding: 10px 20px;
margin: 0 10px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
}
.pagination-btns button:hover {
background-color: #005d8d;
}
@media (max-width: 768px) {
.liste-produits {
grid-template-columns: 1fr;
}
}
</style>
<div class= »liste-produits » id= »liste-produits-<?php echo $categorie_id; ?> »>
<?php
$i = 0;
foreach ($produits as $produit) {
$image = »;
if (!empty($produit->image_url)) {
$image = esc_url($produit->image_url);
} elseif (!empty($produit->image_produit)) {
$image = esc_url(wp_upload_dir()[‘baseurl’] . ‘/’ . ltrim($produit->image_produit, ‘/’));
}
$nom = esc_html($produit->nom_produit);
$prix = esc_html($produit->prix);
$url_detail = site_url(‘/?page_id=481&id=’ . $produit->id);
echo «
<div class=’produit produit-item categorie-{$categorie_id}’ data-index=’$i’ style=’display: none;’>
<a href=’$url_detail’>
<img src=’$image’ alt=’$nom’ width=’200′>
</a>
<h3>$nom</h3>
<p><strong>Prix :</strong> $prix MAD</p>
</div> »;
$i++;
}
?>
</div>
<div class= »pagination-btns »>
<button id= »afficher-moins-<?php echo $categorie_id; ?> » style= »display:none; »>Afficher Moins</button>
<button id= »afficher-plus-<?php echo $categorie_id; ?> »>Afficher Plus</button>
</div>
<script>
(function() {
const produits = document.querySelectorAll(« .produit-item.categorie-<?php echo $categorie_id; ?> »);
const btnPlus = document.getElementById(« afficher-plus-<?php echo $categorie_id; ?> »);
const btnMoins = document.getElementById(« afficher-moins-<?php echo $categorie_id; ?> »);
const produitsParPage = 4;
let visible = produitsParPage;
function afficherProduits() {
produits.forEach((el, i) => {
el.style.display = i < visible ? « block » : « none »;
});
btnMoins.style.display = visible > produitsParPage ? « inline-block » : « none »;
btnPlus.style.display = visible < produits.length ? « inline-block » : « none »;
}
btnPlus.addEventListener(« click », () => {
visible += produitsParPage;
afficherProduits();
});
btnMoins.addEventListener(« click », () => {
visible -= produitsParPage;
if (visible < produitsParPage) visible = produitsParPage;
afficherProduits();
});
afficherProduits();
})();
</script>
<?php
return ob_get_clean();
}
add_shortcode(‘afficher_produits’, ‘afficher_produits_par_categorie_shortcode’);