Link : https://fujikyo.com.vn/wp-login.php?loggedout=true&wp_lang=vi
user : Admin An
Pass : 11111222223344zzxxdfg
Link : https://fujikyo.com.vn/wp-admin/edit.php?post_type=b2bking_conversation
List Conversation donot not show phone and campany. ( image_table_show_data.png )
Link : https://fujikyo.com.vn/wp-admin/edit.php?post_type=b2bking_quote_field
This is code:
// Add custom meta box to b2bking_conversation post type
function add_b2bking_custom_fields_meta_box() {
add_meta_box(
'b2bking_conversation_fields', // Meta box ID
'Conversation Details', // Meta box Title
'render_b2bking_custom_fields_meta_box', // Callback function
'b2bking_conversation', // Post type
'normal', // Context
'high' // Priority
);
}
add_action('add_meta_boxes', 'add_b2bking_custom_fields_meta_box');
// Render Meta Box content
function render_b2bking_custom_fields_meta_box($post) {
// Add nonce for security
wp_nonce_field('b2bking_custom_fields_nonce', 'b2bking_custom_fields_nonce');
// Get existing values
$company_name = get_post_meta($post->ID, 'b2bking_custom_field_2224', true);
$customer_email = get_post_meta($post->ID, 'b2bking_request_custom_quote_email', true);
$customer_phone = get_post_meta($post->ID, 'b2bking_custom_field_2220', true);
?>
<div style="margin: 20px 0;">
<p>
<label style="display: block; margin-bottom: 5px;"><strong>Company Name:</strong></label>
<input type="text"
name="b2bking_custom_field_2224"
value="<?php echo esc_attr($company_name); ?>"
style="width: 100%;">
</p>
<p>
<label style="display: block; margin-bottom: 5px;"><strong>Customer Email:</strong></label>
<input type="email"
name="b2bking_request_custom_quote_email"
value="<?php echo esc_attr($customer_email); ?>"
style="width: 100%;">
</p>
<p>
<label style="display: block; margin-bottom: 5px;"><strong>Customer Phone:</strong></label>
<input type="text"
name="b2bking_custom_field_2220"
value="<?php echo esc_attr($customer_phone); ?>"
style="width: 100%;">
</p>
</div>
<?php
}
// Save Meta Box data
function save_b2bking_custom_fields_meta($post_id) {
// Check if nonce is set and valid
if (!isset($_POST['b2bking_custom_fields_nonce']) ||
!wp_verify_nonce($_POST['b2bking_custom_fields_nonce'], 'b2bking_custom_fields_nonce')) {
return;
}
// Check if autosaving
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// Check user permissions
if (!current_user_can('edit_post', $post_id)) {
return;
}
// Check if correct post type
if (get_post_type($post_id) !== 'b2bking_conversation') {
return;
}
// Save company name
if (isset($_POST['b2bking_custom_field_653732'])) {
$company_name = sanitize_text_field($_POST['b2bking_custom_field_2224']);
update_post_meta($post_id, 'b2bking_custom_field_2224', $company_name);
// update_post_meta($post_id, '_b2bking_custom_field_653732', $company_name);
}
// Save customer email
if (isset($_POST['b2bking_request_custom_quote_email'])) {
$customer_email = sanitize_email($_POST['b2bking_request_custom_quote_email']);
update_post_meta($post_id, 'b2bking_request_custom_quote_email', $customer_email);
// update_post_meta($post_id, '_b2bking_request_custom_quote_email', $customer_email);
}
// Save customer phone
if (isset($_POST['b2bking_custom_field_653730'])) {
$customer_phone = sanitize_text_field($_POST['b2bking_custom_field_2220']);
update_post_meta($post_id, 'b2bking_custom_field_2220', $customer_phone);
// update_post_meta($post_id, '_b2bking_custom_field_653730', $customer_phone);
}
}
add_action('save_post', 'save_b2bking_custom_fields_meta');
function custom_b2bking_show_column_data($column, $post_id) {
switch ($column) {
case 'company_name':
echo esc_html(get_post_meta($post_id, 'b2bking_custom_field_2224', true) ?: 'N/A');
break;
case 'customer_email':
echo esc_html(get_post_meta($post_id, 'b2bking_request_custom_quote_email', true) ?: 'N/A');
break;
case 'customer_phone':
echo esc_html(get_post_meta($post_id, 'b2bking_custom_field_2220', true) ?: 'N/A');
break;
}
}
add_action('manage_b2bking_conversation_posts_custom_column', 'custom_b2bking_show_column_data', 10, 2);
// 2️⃣ Thêm các cột mới vào bảng Conversations
function custom_b2bking_add_columns($columns) {
$columns['company_name'] = __('Tên Công Ty', 'b2bking');
$columns['customer_email'] = __('Email', 'b2bking');
$columns['customer_phone'] = __('Số Điện Thoại', 'b2bking');
return $columns;
}
add_filter('manage_edit-b2bking_conversation_columns', 'custom_b2bking_add_columns');