skip to Main Content

I put product status and other info in short description field on wp all import for all products like this:

URL: <a href="https://www.msi.com/Graphics-card/GeForce-GTX-1650-GAMING-4G/Specification" target="_blank" rel="noopener noreferrer">Производител линк</a>
 <i class="fa fa-check" aria-hidden="true"></i> Наличен <i class="fa fa-truck" aria-hidden="true"></i> Доставка 1-3 дни

avaliable

I want if product category is Videocards to change product status and icon to "call" insted of "avaliable" like this:

URL: <a href="https://www.msi.com/Graphics-card/GeForce-GTX-1650-GAMING-4G/Specification" target="_blank" rel="noopener noreferrer">Производител линк</a>
 <i class="fa fa-volume-control-phone" aria-hidden="true"></i> Обадете се <i class="fa fa-truck" aria-hidden="true"></i> Доставка 1-3 дни

call

Any way to do this with custom function in wp all import or in function.php file of my active child theme?

2

Answers


  1. Chosen as BEST ANSWER

    The above code doesn't work for me, so I had to modify it, and here's a working code. Thanks to Hamid Reza Yazdani for the guidance.

    function magic_custom_text( $post_excerpt ) {   
        if ( is_product() && has_term( 'VIDEO CARD', 'product_cat' ) ) {
          return str_replace( '<i class="fa fa-check" aria-hidden="true"></i> Наличен ', '<i class="fa fa-volume-control-phone" aria-hidden="true"></i> Обадете се ', $post_excerpt );
        } else {
            return $post_excerpt;
        }
    }
    add_filter('woocommerce_short_description', 'magic_custom_text', 10, 1);
    

  2. You can use the following code:

    <?php
    add_filter( 'woocommerce_short_description', 'ywp_custom_single_excerpt' );
    function ywp_custom_single_excerpt( $description ) {
        global $product;
    
        $categories = array( 'videocards' ); // You can add more categories
    
        if( has_term( $categories, 'product_cat', $product ) ) {
            return str_replace( '<i class="fa fa-check" aria-hidden="true"></i> Наличен ', '<i class="fa fa-volume-control-phone" aria-hidden="true"></i> Обадете се ', $description );
        }
    
        return $description;
    }
    

    Code goes in the functions.php file of your active theme/child theme. Tested and works.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search