Append text to product title if product has product-tag on cart in WooCommerce

后端 未结 1 1833
忘掉有多难
忘掉有多难 2021-01-23 09:18

I\'m trying to append text to WooCommerce product title in the cart if products has a specific tag.

This is what i have. I mis the conditional code.



        
相关标签:
1条回答
  • 2021-01-23 09:39
    function add_udstilling_below_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
        $product_id = $cart_item['product_id'];
    
        /* Uncomment for debug purposes
        $terms = wp_get_post_terms( $product_id, 'product_tag' );
        echo '<pre>', print_r($terms, 1), '</pre>';
        */
    
        if ( has_term( 'udstillingsmodel', 'product_tag', $product_id ) ) {
            $item_name = $item_name . ' (test)';
        }
    
        return $item_name;
    }
    add_filter( 'woocommerce_cart_item_name', 'add_udstilling_below_cart_item_name', 10, 3 );
    
    0 讨论(0)
提交回复
热议问题