简体   繁体   中英

Change product status Woocommerce in short description field

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?

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM