Last active
January 23, 2018 13:49
-
-
Save gregoirenoyelle/8a98c10323b2f200508209907a217c22 to your computer and use it in GitHub Desktop.
Exemples avec filter dans WooCommerce
This file contains 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
<?php | |
//* Extrait de la fonction wp_add_to_cart_message dans le fichier woocommerce/includes/wc-cart-functions.php | |
//* Ici on se concentre sur le `apply_filters` pour la redirection native. Elle est éditable avec le hook. | |
// Output success messages | |
if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) { | |
$return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) ); | |
$message = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue shopping', 'woocommerce' ), esc_html( $added_text ) ); | |
} else { | |
$message = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( wc_get_page_permalink( 'cart' ) ), esc_html__( 'View cart', 'woocommerce' ), esc_html( $added_text ) ); | |
} |
This file contains 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
<?php | |
//* A mettre dans un fichier le fichier functions.php, dans votre thème. | |
/** | |
* Masquer le titre sur la page produit | |
* @author Grégoire Noyelle | |
* @link https://docs.woocommerce.com/document/conditional-tags/ | |
*/ | |
function gn_masquer_titre_page() | |
{ | |
if( !is_shop() ) { // Si ce n'est pas la page boutique, l'afficher | |
return true; | |
} | |
} | |
add_filter( 'woocommerce_show_page_title', 'gn_masquer_titre_page' ); |
This file contains 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
<?php | |
/** | |
* Retirer des onglets sur la page produit | |
* @author Grégoire Noyelle | |
* @link https://docs.woocommerce.com/document/editing-product-data-tabs/ | |
* @todo voir le fichier: /woocommerce/templates/single-product/tabs/tabs.php avec la fonction woocommerce_product_tabs | |
* @todo voir le fichier: /woocommerce/includes/wc-template-functions.php avec la fonction woocommerce_default_product_tabs | |
*/ | |
add_filter( 'woocommerce_product_tabs', 'gn_remove_product_tabs', 98 ); | |
function gn_remove_product_tabs( $tabs ) { | |
//* Supprimer des onglets natif: 'description', 'reviews', 'additional_information' | |
unset( $tabs['reviews'] ); // Retirer les avis | |
//* Renommer des onglets natif: 'description', 'reviews', 'additional_information' | |
$tabs['additional_information']['title'] = __('Informations'); | |
// Ajouter un nouvel onglet | |
$tabs['composition'] = array( | |
'title' => __( 'Composition', 'woocommerce' ), | |
'priority' => 50, | |
'callback' => 'gn_contenu_nouvel_onglet' | |
); | |
return $tabs; | |
} | |
function gn_contenu_nouvel_onglet() { | |
echo '<h2>Custom Description</h2>'; | |
echo '<p>Here\'s a custom description</p>'; | |
} |
This file contains 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
<?php | |
//* A mettre dans un fichier le fichier functions.php, dans votre thème. | |
/** | |
* Redirection continuer à faire les courses | |
* @author Grégoire Noyelle | |
* Voir fichier /woocommerce/includes/wc-cart-functions.php | |
*/ | |
function gn_custom_continue_shopping_redirect_url ( $url ) { | |
$url = bloginfo('url') . "/boutique/"; // changer le lien ici | |
return $url; | |
} | |
add_filter('woocommerce_continue_shopping_redirect', 'gn_custom_continue_shopping_redirect_url'); | |
/** | |
* Redirection pour Panier vide | |
* @author Grégoire Noyelle | |
*/ | |
function gn_wc_empty_cart_redirect_url( $url ) { | |
$url = bloginfo('url') . "/boutique/"; // changer le lien ici | |
return $url; | |
} | |
add_filter( 'woocommerce_return_to_shop_redirect', 'gn_wc_empty_cart_redirect_url' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment