簡體   English   中英

Woocommerce 產品數量簡碼不適用於移動瀏覽器

[英]Woocommerce product qty shortcode not working on mobile browsers

我有一個網站,上面有這個簡碼:

if( !function_exists('show_specific_product_quantity') ) {

function show_specific_product_quantity( $atts ) {

    // Shortcode Attributes
    $atts = shortcode_atts(
        array(
            'id' => '', // Product ID argument
        ),
        $atts,
        'product_qty'
    );

    if( empty($atts['id'])) return;

    $stock_quantity = 0;

    $product_obj = wc_get_product( intval( $atts['id'] ) );
    $stock_quantity = $product_obj->get_stock_quantity();

    if( $stock_quantity > 0 ) {
        return $stock_quantity;
    } else {
        return 0;
    }

}

add_shortcode( 'product_qty', 'show_specific_product_quantity' );}

它顯示了產品 ID 的當前庫存水平,它在桌面瀏覽器上完美運行,但在移動瀏覽器上它始終只顯示最大庫存水平。

它只是像這樣使用:

[product_qty id='2329']

每個桌面瀏覽器,包括 Chrome 和 Elementors 響應模式中的模擬移動視口,都能正確顯示。 即使在 Chrome 移動版上,如果將其設置為桌面模式,也會顯示正確的庫存水平。 它僅在本機移動瀏覽器上似乎不起作用。

為什么會這樣?

原來這是一個奇怪的緩存問題,是由 Siteground 的優化插件引起的。 我還沒有弄清楚這三個緩存選項是否是原因,但我會在我這樣做時更新這個答案。

它還阻止了自定義添加到購物車鏈接的工作,同樣僅在移動設備中。 這是一個奇怪的問題,我將向 Siteground 報告。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM