如何编辑WooCommerce中可变产品的购物车功能


How to edit function of add to cart of variable product in WooCommerce?

我尝试在WooCommerce中找到"Add to card"按钮的php文件,但无法找到它们。

我想添加自定义代码来选择自定义框架用于人们将要购买的图片。

按产品类型更改产品档案中的添加到购物车文本这里是一个完整的示例

根据您的需要更改这一行!

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