Bạn muốn thay đổi text mặc định của Woocommerce ,hay khi không nhập sản phẩm, giá để 0đ hoặc chuyển text mặc định “add to cart” thành Liên hệ,hay text tùy ý bạn.Bạn có thể sử dụng đoạn code sau trong file functions.php của theme hoặc tạo 1 plugin nhúng đoạn code sau vào.
add_filter( 'woocommerce_product_add_to_cart_text', 'sw_product_add_to_cart_text', 10, 2 ); add_filter( 'woocommerce_product_single_add_to_cart_text', 'sw_product_add_to_cart_text', 10, 2 ); function sw_product_add_to_cart_text( $product) { global $product; if ( $product->get_price() == 0 || empty( $product->get_price() ) ) { return __( 'Liên hệ', 'woocommerce' ); } else { return __( 'Mua hàng', 'woocommerce' ); } }
Chuyển giá thành Liên hệ khi hết hàng trong woocommerce
function swwordpress_oft_custom_get_price_html( $price, $product ) { global $product; if ( !is_admin() && !$product->is_in_stock()) { $price = '<span class="amount">' . __( 'Liên hệ', 'woocommerce' ) . '</span>'; } return $price; } add_filter( 'woocommerce_get_price_html', 'wordpress_oft_custom_get_price_html', 99, 2 );