add_action( 'wp_enqueue_scripts', 'child_enqueue_styles', 15 );
function custom_questions_answers_tab( $tabs ) {
$tabs['questions_answers'] = array(
'title' => __( 'Questions & Answers', 'text-domain' ),
'callback' => 'custom_questions_answers_tab_content',
'priority' => 50,
);
return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'custom_questions_answers_tab' );
function custom_questions_answers_tab_content() {
global $product;
// Display form to submit a question
echo '<form action="" method="post" class="question-form">';
echo '<label for="question">Ask a question:</label>';
echo '<textarea name="question" id="question"></textarea>';
echo '<input type="hidden" name="product_id" value="' . $product->get_id() . '">';
echo '<input type="submit" value="Submit">';
echo '</form>';
// Display list of previous questions and answers
$questions = get_questions_and_answers_for_product( $product->get_id() );
if ( ! empty( $questions ) ) {
echo '<ul class="questions-answers">';
foreach ( $questions as $question ) {
echo '<li>';
echo '<p class="question">' . $question['question'] . '</p>';
if ( ! empty( $question['answer'] ) ) {
echo '<p class="answer">' . $question['answer'] . '</p>';
}
echo '</li>';
}
echo '</ul>';
}
}
function get_questions_answers_for_product( $product_id ) {
echo 'Hello World';
global $wpdb;
$questions_answers = $wpdb->get_results( $wpdb->prepare( "SELECT question, answer FROM {$wpdb->prefix}questions_answers WHERE product_id = %d", $product_id ) );
return $questions_answers;
}
I'm using Astra pro theme.
Can you guide me. What should i change here to get it done exactly what i expect. Initially i had uncaught error and function undefined error. Finally it has been solved. But the questions which i typed is not showing up for the admin to answer.