如何在WooCommerce中编辑添加到变量产品的购物车功能?

时间:2016-10-27 11:18:17

标签: php wordpress woocommerce

我试过在WooCommerce中找到“添加到卡片”按钮的php文件,但无法找到它们。

我想添加自定义代码,为要购买的图片选择自定义框架

1 个答案:

答案 0 :(得分:0)

按产品类型更改产品档案中的添加到购物车文本以下是Complete Example

根据您的需要更改此行!

case 'variable':
                return __( 'Select options', 'woocommerce' ); 

完整代码将以下内容添加到functions.php文件并编辑按钮文字。

add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
    function custom_woocommerce_product_add_to_cart_text() {
        global $product;

        $product_type = $product->product_type;

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

    }