2
ショップページのページを変更し、ページスクロールでajaxを使用して商品を読み込むカスタムコードを追加しました。私のサイトは多言語で、私はWPMLを使用しています。コードは既定の言語では問題なく動作していますが、他の言語では、その言語の製品を表示する代わりに、既定の言語、つまり英語の製品を表示します。翻訳された商品が特定の言語に対応していることを示すことを意味します。ここで WP_Queryで現在の言語のwoocommerce製品を取得するには?
は、私のコードのAjaxコードです:var $ = jQuery;
var flag=1;
var limit=0;
$(window).scroll(function(){
if($(window).scrollTop() == $(document).height() - $(window).height()){
limit++;
if(flag==1)
{
$(".lazy_lode_img").css('display','block');//display loading image
$.ajax({
url:"<?php echo get_stylesheet_directory_uri();?>/ajax.php", // ajax page
type:'POST',
data:{ 'paged':limit}, // send page no
dataType:"html",
success: function(product_data){
//alert(product_data);
if(product_data!=0)
{
$(".shop-products.row.grid-view").append(product_data);
$(".lazy_lode_img").css('display','none');
}
else
{
flag=0;
// $('#k_test').append('<div class="news" id="no_news" style="text-align:center;">NO MORE PRODUCT</div>');
$(".lazy_lode_img").remove();
}
}
});
}
}
});
そして、ここに私のPHPコードです:それはの製品を取得するように、私は言語コードを渡す必要がありますどこ私は理解していない
$page_no = $_POST['paged'];
$post_per_page=6;
$args = array(
'posts_per_page' => $post_per_page,//set post per page
'paged' => $page_no,//set offset for limit
'post_type' => 'product',
'post_status'=>'publish',
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) : $query->the_post();
/*$price = get_post_meta($query->post->ID, '_regular_price', true);
$price=round($price,2);
if ((int) $price == $price)
{
$price=$price.'.00';
}*/
?>
<div class="item-col col-xs-6 col-md-4 col-sm-4 post-6303 product type-product status-publish has-post-thumbnail product_cat-all-products product_cat-tarts instock shipping-taxable purchasable product-type-simple">
<div class="product-wrapper product-wrapper2">
<div class="list-col4">
<div class="product-image">
<a class="twoimg" href="<?php echo get_permalink($query->post->ID);?>" title="Blueberry Frangipane Tart">
<?php echo get_the_post_thumbnail($query->post->ID, 'shop_catalog');?>
</a>
</div>
<div class="home-product-title">
<h2 class="product-name">
<a href="<?php echo get_permalink($query->post->ID);?>" style="color:black;"><?php echo $query->post->post_title;?></a>
</h2>
<span class="arrow-img"></span>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<?php
endwhile;
}
else
{
echo '0';
}
フロントエンドで現在選択されている言語。
これは、https://wpml.org/forums/topic/show-default-languageplugin-if-not-translated/ –
私はswitch_lang()を使って試しましたが、英語版製品を表示していました。 。 –