Cách thêm Advanced custom fields dưới tiêu đề Product Woocommerce

Đánh giá post

Hướng dẫn Cách thêm Advanced custom fields dưới tiêu đề Product Woocommerce, add advanced custom fields below tittle product woocommerce, Show ACF field in WooCommerce Archive Listing, Add custom field in WooCommerce single product page

 

Chèn đoạn code sau vào file funstions.php , đoạn code dưới sẽ xóa tiêu đề mặc định của WooCommercethêm tiêu đề mới, custom fields dưới phần giá.

function sly_switch_loop_title(){
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
add_action( 'woocommerce_after_shop_loop_item_title', 'sly_template_loop_product_title', 15 );
}
add_action( 'woocommerce_before_shop_loop_item', 'sly_switch_loop_title' );

function sly_template_loop_product_title() {
echo '<h2 class="woocommerce-loop-product__title">' . get_the_title() . '</h2>';
echo the_field( 'tien_nghi' );
}

đoạn code đơn giản hơn, ko xóa tiêu đề mà chỉ thêm custom fields

Thay tien_nghi bằng tên custom fields của bạn

function sly_switch_loop_title(){
add_action( 'woocommerce_after_shop_loop_item_title', 'sly_template_loop_product_title', 15 );
}
add_action( 'woocommerce_before_shop_loop_item', 'sly_switch_loop_title' );
function sly_template_loop_product_title() {
echo the_field( 'tien_nghi' );
echo '<p>' . get_field('sophongtam') . '</p>';
}
Đánh giá post


Trả lời