How do I change text in the product buttons of cat

2019-08-02 21:31发布

I have not been able to edit the buttons as there is not way to use visual composer for the category page.

I want to enter the name of each product instead of 'view product' which is currently on the button.

Screenshot:

2条回答
来,给爷笑一个
2楼-- · 2019-08-02 22:16

you can change the woocommerce button name (View products,Buy product,Add to cart,Select options,Read more) by using below function.

Add below in theme function.php file

add_filter( 'woocommerce_product_add_to_cart_text' , 'sm_woocommerce_product_add_to_cart_text' );
/**
 * sm_woocommerce_product_add_to_cart_text
*/
function sm_woocommerce_product_add_to_cart_text() {
    global $product;

    $product_type = $product->product_type;

    $id = $product->get_id();
    $product = wc_get_product( $id );

    switch ( $product_type ) {
        case 'external':
            return __( 'Buy product', 'woocommerce' );
        break;
        case 'grouped':
            //return __( 'View products', 'woocommerce' );
            return __(  $product->get_title(), 'woocommerce' );
        break;
        case 'simple':
            return __( 'Add to cart', 'woocommerce' );
        break;
        case 'variable':
            return __( 'Select options', 'woocommerce' );
        break;
        default:
            return __( 'Read more', 'woocommerce' );
    }

}
查看更多
地球回转人心会变
3楼-- · 2019-08-02 22:18

You can find the needed text in the category.php file. Sometimes the text is hard coded in the .php files.

For easy String search, you can use this plugin https://wordpress.org/plugins/string-locator/ the plugin find the necessary text and the hard coded location where it is.

查看更多
登录 后发表回答