admin管理员组

文章数量:1291202

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 3 years ago.

Improve this question

I created a custom metabox for the same woocommerce products, but I would like the community's help so that this metabox appears on the front end.

fuctions.php

add_action( 'woocommerce_product_options_advanced', 'misha_adv_product_options');
function misha_adv_product_options(){
 
    echo '<div class="options_group">';
 
    woocommerce_wp_text_input( array(
        'id'                => 'misha_plugin_version',
        'value'             => get_post_meta( get_the_ID(), 'misha_plugin_version', true ),
        'label'             => 'Plugin version',
        'description'       => 'Description when desc_tip param is not true'
    ) );
 
    echo '</div>';
 
}
 
 
add_action( 'woocommerce_process_product_meta', 'misha_save_fields', 10, 2 );
function misha_save_fields( $id, $post ){
 
    //if( !empty( $_POST['super_product'] ) ) {
        update_post_meta( $id, 'misha_plugin_version', $_POST['misha_plugin_version'] );
    //} else {
    //  delete_post_meta( $id, 'super_product' );
    //}
 
}

index.php

<?php  
                $args = array(
                    'orderby'        => 'date',
                    'post_type'      => 'product',
                    'posts_per_page' => 10,
                );

                $loop = new WP_Query( $args );

                while ( $loop->have_posts() ) : $loop->the_post();
                    global $product;
                    echo '<br />
                        <div class="col">
                            <div class="card-product">
                                <a href="'.get_permalink().'">
                                    '.woocommerce_get_product_thumbnail().' 
                                   
                                   <h1>'.get_the_title().'</h1>
                                </a>
                                <a href="**I need the result of my metabox to appear here**">Visualizar demo</a>
                            </div>
                        </div>';
                        
                endwhile;
                
                wp_reset_query();
            ?>

本文标签: woocommerce offtopicHow to display the result of a custom metabox in the frontend