Nhu cầu thiết kế website bán hàng qua mạng bằng WordPress trong vài năm gần đây trở nên tăng cao và phổ biến. Để làm website bán hàng đơn giản bằng WordPress thì không khó nhưng để tạo website bán hàng chuyên nghiệp thì bạn cần biết cụ thể về Woocommerce sẽ giúp bạn custom giao diện và chức năng theo ý mình.

Sau đây Sơn Web sẽ hướng dẫn bạn 1 số hàm trong woocommerce

  1. Thay đổi text Thêm vào giò trong woocommerce

Đối với woocommerce < 2.1 bạn sử dụng functions sau để thay đổi trên trang chi tiết sản phẩm :

[crayon] add_filter( ‘add_to_cart_text’, ‘woo_custom_cart_button_text’ ); // < 2.1

function woo_custom_cart_button_text() {

return __( ‘My Button Text’, ‘woocommerce’ );

}
[/crayon] Đối với Woocommerce > 2.1

[crayon] add_filter( ‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’ ); // 2.1 +

function woo_custom_cart_button_text() {

return __( ‘Mua ngay’, ‘woocommerce’ );

}
[/crayon]

Thay đổi text add to cart hay thêm vào giỏ trong vòng lặp như danh mục sản phẩm , trang chủ, và sản phẩm
Đối với woocommerce < 2.1

[crayon]

add_filter( ‘add_to_cart_text’, ‘woo_archive_custom_cart_button_text’ ); // < 2.1 function woo_archive_custom_cart_button_text() { return __( 'My Button Text', 'woocommerce' ); } [/crayon] Đối với woocommerce > 2.1
[crayon]

dd_filter( ‘woocommerce_product_add_to_cart_text’, ‘woo_archive_custom_cart_button_text’ ); // 2.1 +

function woo_archive_custom_cart_button_text() {

return __( ‘My Button Text’, ‘woocommerce’ );

}

[/crayon]

Thay đổi Add to cart trên danh mục hay post type trong hàm
[crayon] add_filter( ‘woocommerce_product_add_to_cart_text’ , ‘custom_woocommerce_product_add_to_cart_text’ );
/**
* custom_woocommerce_template_loop_add_to_cart
*/
function custom_woocommerce_product_add_to_cart_text() {
global $product;

$product_type = $product->product_type;

switch ( $product_type ) {
case ‘external’:
return __( ‘Mua ngay’, ‘woocommerce’ );
break;
case ‘grouped’:
return __( ‘Xem sản phẩm’, ‘woocommerce’ );
break;
case ‘simple’:
return __( ‘Add to cart’, ‘woocommerce’ );
break;
case ‘variable’:
return __( ‘Select options’, ‘woocommerce’ );
break;
default:
return __( ‘Xem thêm’, ‘woocommerce’ );
}

}
[/crayon]

Rate this post

Trả lời

Chat Zalo

0932644183

Chat Zalo

0932644183