1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
// Display Fields add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' ); // Save Fields add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' ); function woo_add_custom_general_fields() { global $woocommerce, $post; echo '<div class="options_group">'; // Text Field woocommerce_wp_text_input( array( 'id' => '_khuyen_mai', 'label' => __( 'Khuyến mãi', 'woocommerce' ), 'placeholder' => 'Thông tin khuyến mãi', 'desc_tip' => 'true', 'description' => __( '', 'woocommerce' ) ) ); // Textarea woocommerce_wp_textarea_input( array( 'id' => '_thi_truong_phuc_vu', 'label' => __( 'Thị trường phục vụ', 'woocommerce' ), 'placeholder' => '', 'description' => __( '', 'woocommerce' ) ) ); echo '</div>'; } function woo_add_custom_general_fields_save( $post_id ){ // Text Field $woocommerce_text_field = $_POST['_khuyen_mai']; if( !empty( $woocommerce_text_field ) ) update_post_meta( $post_id, '_khuyen_mai', esc_attr( $woocommerce_text_field ) ); // Textarea $woocommerce_textarea = $_POST['_thi_truong_phuc_vu']; if( !empty( $woocommerce_textarea ) ) update_post_meta( $post_id, '_thi_truong_phuc_vu', esc_html( $woocommerce_textarea ) ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
function show_khuyen_mai(){ global $post; $get_khuyen_mai = get_post_meta($post->ID,"_khuyen_mai",true); $_thi_truong_phuc_vu = get_post_meta($post->ID,"_thi_truong_phuc_vu",true); ?> <div class="khuyen-mai"> <h2>Khuyến mãi</h2> <p><?php echo $get_khuyen_mai; ?></p> </div> <div class="thi-truong-phuc-vu"> <?php echo $_thi_truong_phuc_vu; ?> </div> <?php } add_action("woocommerce_single_product_summary","show_khuyen_mai",21); |
Mọi sự sao chép xin ghi rõ nguồn là fcwordpress.net
Chuyên trang về wordpress: hướng dẫn thiết kế theme, plugin, thủ thuật wordpress