How to insert categories, sale badges or custom text into the WooCommerce archive layout - no plugin

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ม.ค. 2025

ความคิดเห็น • 4

  • @slingsandarrows
    @slingsandarrows ปีที่แล้ว

    What would I change the code to look like if I wanted to add a custom badge to just a single category?

  • @majdaj.7028
    @majdaj.7028 ปีที่แล้ว

    Awesome tutorial, thank you for making this. quick question: currently my products price is at the top (Above the title and categories) Any idea how to place it below the product name :)

  • @gosales
    @gosales ปีที่แล้ว

    How do you get it to come up in a catagory page in woo?

  • @BruceYoung
    @BruceYoung  2 ปีที่แล้ว +1

    The code - function by_woo_additions() {
    global $post;
    $terms = get_the_terms( $post->ID, 'product_cat' );
    $terms_tag = get_the_terms( $post->ID, 'product_tag' );
    if ( $terms ) {
    foreach( $terms as $term ){
    $cat_name[] = $term->name;
    }
    $the_categories = implode(' | ', $cat_name );
    echo '' . $the_categories . '';
    }
    $sale_price = get_post_meta( $post->ID, '_sale_price', true);
    if ( $sale_price> 0 ) {
    echo 'SALE';
    }
    }
    add_action( 'woocommerce_shop_loop_item_title', 'by_woo_additions', 1 );
    function by_woo_additions_a() {
    global $post;
    $terms = get_the_terms( $post->ID, 'product_cat' );
    $terms_tag = get_the_terms( $post->ID, 'product_tag' );
    if ( $terms ) {
    foreach( $terms as $term ){
    if ( $term->name == 'Beanie' || $term->name == 'Hoodies' ) {
    echo 'Head Warmer';
    }
    }
    }
    }
    add_action( 'woocommerce_after_shop_loop_item_title', 'by_woo_additions_a', 5 );