我正在尝试更新woocommerce弃用的模板。除了这个之外我管理了大部分模板。也许有些人可以帮助我。非常感谢你。
打开wp调试,我得到了这个。
注意:自3.0版以来,不推荐使用WC_Product :: get_related!请改用wc_get_related_products。
这是现在的实际代码行
$related = $product->get_related( $posts_per_page );
我把它改成了这个
$related = $product->wc_get_related_products( $posts_per_page );
但后来我明白了:
致命错误:调用未定义的方法WC_Product_Simple :: wc_get_related_products()
以下是完整的代码,谢谢。
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $product, $woocommerce_loop;
if ( empty( $product ) || ! $product->exists() ) {
return;
}
$related = $product->wc_get_related_products( $posts_per_page );
if ( sizeof( $related ) == 0 ) return;
$args = apply_filters( 'woocommerce_related_products_args', array(
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'no_found_rows' => 1,
'posts_per_page' => $posts_per_page,
'orderby' => $orderby,
'post__in' => $related,
'post__not_in' => array( $product->id )
) );
$products = new WP_Query( $args );
$woocommerce_loop['columns'] = $columns;
if ( $products->have_posts() ) : ?>
<div class="wc_related sugpro_box products">
<h2><?php esc_html_e( 'Suggestions you might enjoy with this products', 'woocommerce' ); ?></h2>
<div class="pro_foods_list">
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
</div>
</div>
<?php endif;
wp_reset_postdata();
?>
<div class="recip_prod">
<h2>Recipes with this products</h2>
<ul class="recip_list">
<?php
$post_id = get_the_ID();
$nameqry1="select * from wp_posts where ID IN (select r.rec_id from wp_posts as p , wp_recipes as r where p.ID=r.post_id AND p.ID=".$post_id.") AND `post_status`='publish'";
$Rquery = mysqli_query($mysqli,$nameqry1);
if(mysqli_num_rows($Rquery) > 0)
{
while( $rows = mysqli_fetch_assoc($Rquery))
{ ?>
<li><a href="<?php echo get_bloginfo('url');?>/search-recipes/?rc-page=<?php echo $rows['ID']?>"><?php echo $rows['post_title'];?></a></li>
<?php }
}else{
echo "This Product Recipes Not Available";
}
?>
</ul>
</div>