تماس با ما: 02166057992 چت آنلاین   ورود

کد نمایش محصولات مرتبط در بین مطالب سایت – WooCommerce


این کد را داخل فایل فانکشن بگذارید

add_action('add_meta_boxes"https://wp-parsi.com/,'meta_idprod_related"https://wp-parsi.com/);
add_action('save_post"https://wp-parsi.com/ , 'save_meta_id_related"https://wp-parsi.com/);
function meta_idprod_related(){
    $qpid= array('product"https://wp-parsi.com/);
    foreach ($qpid as $qid) {
        add_meta_box('id_rel_product"https://wp-parsi.com/, 'آی دی محصول مرتبط "https://wp-parsi.com/, 'related_id_product"https://wp-parsi.com/, $qid, 'side"https://wp-parsi.com/, '"https://wp-parsi.com/);

    }
}
function related_id_product($post){
    
    $relat=get_post_meta($post ->ID,'id_rel"https://wp-parsi.com/,true);
		?> 
     <input class="input "https://wp-parsi.com/ name="txt_id_rel"https://wp-parsi.com/ type="text"https://wp-parsi.com/ value="<?php  echo $relat?>"https://wp-parsi.com/ />
<?php
}
function save_meta_id_related($post_id){
   
    if (isset($_POST['txt_id_rel"https://wp-parsi.com/]) && !empty($_POST['txt_id_rel"https://wp-parsi.com/])){
        update_post_meta($post_id , 'id_rel"https://wp-parsi.com/,sanitize_text_field($_POST['txt_id_rel"https://wp-parsi.com/]));
}
} 

این کد را جایی که میخواهید نمایش داده شود .فقط جای نامک دسته بندی نامک دسته مورد نظر را وارد کنید به انگلیسی

 

	<?php
	$relat=get_post_meta($post ->ID,'id_rel"https://wp-parsi.com/,true);
    $qprod = new WP_Query(array(
        'post_type"https://wp-parsi.com/ => 'product"https://wp-parsi.com/,
        "posts_per_page"https://wp-parsi.com/ => 3,
		'product_cat"https://wp-parsi.com/    =>'نامک دسته بندی"https://wp-parsi.com/,
    ));
    if ($qprod->have_posts()) :
        while ($qprod->have_posts()) : $qprod->the_post(); ?>
    <div class="post-zarcod"https://wp-parsi.com/>
        <figure class="thomb-slid"https://wp-parsi.com/>                      
        <a href="https://wp-parsi.com/<?php the_permalink(); ?>"> <?php the_post_thumbnail(); ?> </a>
        </figure>
        <div class="title-prod-zarcod"https://wp-parsi.com/>
        <a href="https://wp-parsi.com/<?php the_permalink(); ?>">
             <h2><?php the_title(); ?></h2>
        </a>
        </div>

    </div>
    <?php
        endwhile;
        wp_reset_postdata();
    endif; ؟>



منبع: وردپرس

نظرات شما

WhatsApp chat