Để sử dụng bạn copy đoạn code sau vào file functions.php trong thư mục theme bạn đang sử dụng nhé!
function devvn_wc_custom_get_price_html( $price, $product ) { if ( $product->get_price() == 0 ) { if ( $product->is_on_sale() && $product->get_regular_price() ) { $regular_price = wc_get_price_to_display( $product, array( 'qty' => 1, 'price' => $product->get_regular_price() ) ); $price = wc_format_price_range( $regular_price, __( 'Free!', 'woocommerce' ) ); } else { $price = '<a href="#">' . __( 'Liên hệ', 'woocommerce' ) . '</a>'; } } return $price; } add_filter( 'woocommerce_get_price_html', 'devvn_wc_custom_get_price_html', 10, 2 );
add_filter('woocommerce_get_price_html', 'change_sold_out_product_price_html', 100, 2 ); function change_sold_out_product_price_html( $price_html, $product ) { if ( ! $product->is_in_stock() ) { $price_html = __("HẾT HÀNG RỒI", "woocommerce"); } return $price_html; }
Ngoài ra nếu muốn sửa nút “Thêm vào giỏ hàng” hay “Add to cart” thành “Contact Us”. Hãy copy đoạn code sau vào file functions.php
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' ); add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text' ); function woo_custom_cart_button_text() { return __( 'Contact Us', 'woocommerce' ); }
Chúc các bạn thành công!