Favicon BulgaWeb

WooCommerce Snippets

Mis à jour le dimanche 9 août 2020
Temps approximatif de lecture : 2 minutes

Quelques snippets utiles pour WooCommerce

Certaines sources viennent du très bon site BusinessBloomer

Ajouter des notifications d'erreur de champ en ligne

/**
 * @snippet       Remove Add Cart, Add View Product @ WooCommerce Loop
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.6.2
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
  
// First, remove Add to Cart Button 
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
  
// Second, add View Product Button
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_view_product_button', 10 );
  
function bbloomer_view_product_button() {
    global $product;
    $link = $product->get_permalink();
    echo '<a href="' . $link . '" class="button addtocartbutton">Details</a>';
}

Remplacer "Ajouter un panier" par "Voir le produit"

/**
 * @snippet       Remove Add Cart, Add View Product @ WooCommerce Loop
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.6.2
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
  
// First, remove Add to Cart Button  
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
  
// Second, add View Product Button
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_view_product_button', 10 );
  
function bbloomer_view_product_button() {
    global $product;
    $link = $product->get_permalink();
    echo '<a href="' . $link . '" class="button addtocartbutton">Details</a>';
}

Afficher "épuisé" sur les pages en boucle

/**
 * @snippet       Display "Sold Out" on Loop Pages - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=17420
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.4.3
 */
 
add_action( 'woocommerce_before_shop_loop_item_title', 'bbloomer_display_sold_out_loop_woocommerce' );
 
function bbloomer_display_sold_out_loop_woocommerce() {
    global $product;
    if ( !$product->is_in_stock() ) {
        echo '<span class="soldout">' . __( 'SOLD OUT', 'woocommerce' ) . '</span>';
    }
} 

CSS :

.soldout {
    padding: 3px 8px;
    text-align: center;
    background: #222;
    color: white;
    font-weight: bold;
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 12px;
}

Afficher les sous-catégories de produits

/**
 * @snippet       WooCommerce Show Product Subcategories
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=17525
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.4.5
 */
 
add_action( 'woocommerce_after_shop_loop_item_title', 'bbloomer_show_all_subcats', 2 );
  
function bbloomer_show_all_subcats() {
    global $post;        
    $cats = get_the_terms( $post->ID, 'product_cat' );           
    if ( ! empty( $cats ) ) {                
        foreach ( $cats as $term ) {           
            // If parent 116 === cat ID echo subcat name...
            if ( 116 === $term->parent ) { 
                echo $term->name;
            }             
        }
    }        
}

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Suite à la monétisation des mes postes sur un site externe (https://oxyhowto.com/more_hows-categories/french/) sans mon autorisation, les postes sont uniquement visibles avec un compte.
Copyright © 2019 - 2023 Bulgaweb
 | 
Développé par BulgaWeb
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram