haxorqt
Home
Console
Upload
information
Create File
Create Folder
About
:
/
home
/
sc1jaqa5103
/
prod.puv-editions.fr
/
wp-content
/
themes
/
hello-elementor-child
/
Filename :
functions.php
back
Copy
<?php //* Enqueue style.css from child theme function hello_elementor_child_enqueue_scripts() { wp_enqueue_style( 'hello-elementor-child-style', get_stylesheet_directory_uri() . '/style.css', [ 'hello-elementor-theme-style', ], '1.0.0' ); } add_action('wp_enqueue_scripts', 'hello_elementor_child_enqueue_scripts', 20); /** * Modification du libellé UGS */ function translate_woocommerce($translation, $text, $domain) { if ($domain == 'woocommerce') { switch ($text) { case 'SKU': $translation = 'EAN'; break; case 'SKU:': $translation = 'EAN :'; break; } } return $translation; } add_filter('gettext', 'translate_woocommerce', 10, 3); /*** BOUTONS PRODUITS VARIABLES - CLAUDE ***/ function generate_add_cart_btn($ID) { global $product; $url = '?add-to-cart=' . $product->get_id(); $urlRedirect = get_permalink($product->get_id()); if ($product->is_type('simple')) { $url .= '&quantity=1&e-redirect=' . $urlRedirect; return sprintf(get_add_to_cart_btn_template(), $url, __("PAPIER", "woocommerce"), $product->get_price() . ' <span class="woocommerce-Price-currencySymbol">€</span>'); } elseif ($product->is_type('variable')) { $btns = []; $isReverse = false; foreach ($product->get_available_variations() as $key => $variation_data) { if("PAPIER" === $variation_data['attributes']['attribute_support'] || "PAPIER" === $variation_data['attributes']['attribute_pa_support']){ $isReverse = $key !== 0; } $btns[] = generate_add_to_cart_btn($variation_data, $urlRedirect); } if ($isReverse) { $btns = array_reverse($btns); } return implode(' ', $btns); } } /*** SI CONTRIBUTEURS > 3 ALORS COLLECTIF - CLAUDE ***/ function pods_printable_author_name($auteurs) { if (!is_array($auteurs)) { return ''; } if (count($auteurs) > 3) { return 'Collectif'; } $text = implode(', ', array_map(function ($auteur) { return $auteur["post_title"]; }, $auteurs)); return $text; } /*** LISTE COMPLETE DES CONTRIBUTEURS - CLAUDE ***/ function pods_printable_author_name2($auteurs) { if (!is_array($auteurs)) { return ''; } $text = implode(', ', array_map(function ($auteur) { $out = sprintf( '<a href="%s">%s</a>', esc_url(get_permalink($auteur["ID"])), esc_html($auteur["post_title"]) ); return $out; }, $auteurs)); return $text; } /*** AFFICHAGE EAN NUMERIQUE - CLAUDE ***/ function pods_get_numeric_ean($value) { global $product; $ean = ""; if ($product->is_type('variable')) { foreach ($product->get_available_variations() as $variation_data) { foreach ($variation_data['attributes'] as $attr_key => $term_slug) { if (($attr_key === 'attribute_pa_support' || $attr_key === 'attribute_support') && $term_slug === 'NUMÉRIQUE') { $ean = '<hr style="margin-top:10px;"><strong>Version numérique</strong><br />EAN : ' . $variation_data['sku'] . '<br />'; } } } } return $ean; } /*** TELECHARGEMENT EPUB ***/ function add_custom_mime_types($mimes) { $new_file_types = array( 'zip' => 'application/zip', 'mobi' => 'application/x-mobipocket-ebook', 'pdf' => 'application/pdf', 'epub' => 'application/epub+zip' ); return array_merge($mimes, $new_file_types); } add_filter('upload_mimes', 'add_custom_mime_types'); /*** HELPERS - Claude ***/ function get_add_to_cart_btn_template() { $preOrder = has_term('a-paraitre', 'statut') ? 'Précommande' : ''; $btn = <<<HTML <div class="elementor-element elementor-element-3259845 elementor-align-justify elementor-widget elementor-widget-button" data-element_type="widget"> <div class="elementor-widget-container"> <div class="elementor-button-wrapper"> <a href="%s" class="%s" role="button"> <span class="elementor-button-content-wrapper"> <span class="elementor-button-text">%s<br><span class="woocommerce-Price-amount amount"><bdi>%s</bdi></span></span> </span> <span class="preoder_button">$preOrder</span> </a> </div> </div> </div> HTML; return $btn; } function get_btn_add_to_cart_label($attributes, $variant_id) { $label = __("Add to cart", "woocommerce"); foreach ($attributes as $attr_key => $term_slug) { if (($attr_key === 'attribute_pa_support' || $attr_key === 'attribute_support') && (strtoupper($term_slug) === 'PAPIER' || $term_slug === '')) { $label = __("PAPIER", "woocommerce"); } if (($attr_key === 'attribute_pa_support' || $attr_key === 'attribute_support') && ($term_slug === 'NUMÉRIQUE' || levenshtein(strtolower($term_slug), 'numerique') < 3)) { $variant = new WC_Product_Variation($variant_id); $variants = array_map(function ($item) { return $item->get_name(); }, $variant->get_downloads()); usort($variants, function ($a, $b) { return strcmp($b, $a); }); $variantLabel = implode(' & ', $variants); $label = __($variantLabel !== '' ? $variantLabel : "NUMÉRIQUE", "woocommerce"); } if (($attr_key === 'attribute_pa_abonnement' || $attr_key === 'attribute_support') && $term_slug === 'abo1') { $label = __("Abonnement 1 an", "woocommerce"); } if (($attr_key === 'attribute_pa_abonnement' || $attr_key === 'attribute_support') && $term_slug === 'abo2') { $label = __("Abonnement 2 ans", "woocommerce"); } } return $label; } function generate_add_to_cart_btn($variation_data, $urlRedirect) { $btnClass = "elementor-button-link elementor-button elementor-size-md"; $url = '?add-to-cart=' . $variation_data['variation_id']; // The dynamic variation ID (URL) $price = $variation_data['display_price'] . ' <span class="woocommerce-Price-currencySymbol">€</span>'; $button_text = get_btn_add_to_cart_label($variation_data['attributes'], $variation_data['variation_id']); if ($variation_data['is_in_stock'] === false) { $url = "#"; $price = __("ÉPUISÉ", "woocommerce"); $btnClass .= ' product-disable'; } foreach ($variation_data['attributes'] as $attr_key => $term_slug) { $url .= '&quantity=1&e-redirect=' . $urlRedirect; $url .= '&' . $attr_key . '=' . $term_slug; } return sprintf(get_add_to_cart_btn_template(), $url, $btnClass, $button_text, $price); } /** * Add text "Produit en precommande" to cart porduct if a product has status "a-paraitre" * @param $item_name * @param $cart_item * @param $cart_item_key * @return mixed|string */ function generate_custom_text_cart_item_name($item_name, $cart_item, $cart_item_key) { $categories = array('a-paraitre'); if (is_cart() && has_term($categories, 'statut', $cart_item['product_id'])) { $item_name .= '<br /><span style="font-size: 10px;font-style: italic;">' . __("Produit en précommande", "woocommerce") . '</span>'; } return $item_name; } add_filter('woocommerce_cart_item_name', 'generate_custom_text_cart_item_name', 10, 3); /** * Add text "Produit en precommande" to checkout product name if a product has status "a-paraitre" * @param $item_name * @param $cart_item * @param $cart_item_key * @return mixed|string */ function generate_custom_checkout_text_cart_item_name($item_name, $cart_item, $cart_item_key) { $categories = array('a-paraitre'); $pods = pods('product', $cart_item['product_id']); $availabilty_date = date_create($pods->field('date_parution')); if (has_term($categories, 'statut', $cart_item['product_id'])) { $item_name .= '<br /><span style="font-size: 10px;font-style: italic;">' . __("Produit en précommande", "woocommerce") . '</span>'; $item_name .= '<br /><span style="font-size: 10px;font-style: italic;font-weight: bold">' . __("Sortie prévue le: ", "woocommerce") . date_format($availabilty_date, "d/m/y") . '</span>'; } return $item_name; } add_filter('woocommerce_checkout_cart_item_quantity', 'generate_custom_checkout_text_cart_item_name', 10, 3); /** * Add text "Produit en precommande" to list product name in mail order if a product has status "a-paraitre" * @param $item_name * @param $item * @param $false * @return mixed|string */ function generate_custom_order_text_item_name($item_name, $item, $false) { $categories = array('a-paraitre'); $pods = pods('product', $item['product_id']); $availabilty_date = date_create($pods->field('date_parution')); if (has_term($categories, 'statut', $item['product_id'])) { $item_name .= '<br /><span style="font-size: 10px;font-style: italic;">' . __("Produit en précommande", "woocommerce") . '</span>'; $item_name .= '<br /><span style="font-size: 10px;font-style: italic;font-weight: bold">' . __("Sortie prévue le: ", "woocommerce") . date_format($availabilty_date, "d/m/y") . '</span>'; } return $item_name; } add_filter('woocommerce_order_item_name', 'generate_custom_order_text_item_name', 10, 3); /** Index des thématiques **/ function woocommerce_category_index_shortcode() { ob_start(); $args = array( 'taxonomy' => 'product_cat', 'orderby' => 'name', 'show_count' => 1, 'pad_counts' => 1, 'hierarchical' => 1, 'title_li' => '', 'hide_empty' => true ); $categories = get_categories($args); echo '<ul>'; foreach ($categories as $category) { $cat_link = get_term_link($category); echo '<li class="category-index">'; echo '<h2>' . esc_html($category->name) . '</h2>'; echo '<p>' . esc_html($category->description) . '</p>'; echo '<a href="' . esc_url($cat_link) . '" class="arrow">Voir tous les ouvrages</a>'; echo '</li>'; } echo '</ul>'; $output = ob_get_clean(); return $output; } add_shortcode('woocommerce_category_index', 'woocommerce_category_index_shortcode'); /** Chargement du template Contributeur - Ouvrage(s) **/ function afficher_template_personne() { ob_start(); // Récupérer l'ID du contexte actuel (page ou post) $contributeur_id = get_the_ID(); if (empty($contributeur_id)) { echo 'Erreur : Aucun ID de contributeur trouvé dans le contexte actuel.'; return ob_get_clean(); } // Charger l'élément spécifique du Pod "personne" $obj = pods('personne', $contributeur_id); // Remplacez 'personne' par le slug réel de votre Pod // Vérifiez si l'objet Pods est bien chargé if (!$obj->exists()) { echo 'Erreur : Impossible de charger l\'objet Pods pour le contributeur avec l\'ID ' . $contributeur_id; return ob_get_clean(); } // Inclure le fichier template $template_path = get_stylesheet_directory() . '/pods/templates/personne-fiche.php'; if (file_exists($template_path)) { include $template_path; } else { echo 'Le fichier personne-fiche.php est introuvable à : ' . $template_path; } return ob_get_clean(); } add_shortcode('template_personne', 'afficher_template_personne'); /** Tri des publications en ordre antechronologique sur date de parution **/ add_action( 'elementor/query/ouvrages_parution', function( $query ) { global $wpdb; $query->set( 'meta_key', 'date_parution' ); $query->set( 'orderby', "STR_TO_DATE({$wpdb->postmeta}.meta_value,'%m/%d/%Y')" ); $query->set( 'order', 'DESC' ); });