Created
August 6, 2026 16:49
-
-
Save LPerderiset/49ddb9cf4741cf902fa7707b82a9e840 to your computer and use it in GitHub Desktop.
Supprimer le bouton "Ajouter au panier" et ajouter un bouton "Contactez-nous" uniquement pour certains produits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Supprimer le bouton "Ajouter au panier" et ajouter un bouton "Contactez-nous" uniquement pour certains produits | |
| add_action('wp', 'conditionally_replace_add_to_cart_button'); | |
| function conditionally_replace_add_to_cart_button() { | |
| $product_ids = array(123, 456); // Remplacez 123 et 456 par les IDs de vos produits spécifiques | |
| if (is_product() && in_array(get_the_ID(), $product_ids)) { | |
| remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); | |
| add_action('woocommerce_single_product_summary', 'custom_contact_button_single', 30); | |
| } | |
| } | |
| function custom_contact_button_single() { | |
| $contact_page_url = get_permalink(get_page_by_path('contact')); // Assurez-vous que le slug de votre page de contact est "contact" | |
| echo '<a href="' . esc_url($contact_page_url) . '" class="button contact-button">' . __('Contactez-nous', 'woocommerce') . '</a>'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment