简体   繁体   English

Woocommerce 产品数量简码不适用于移动浏览器

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

I've got an with a site, we've got this shortcode on it:我有一个网站,上面有这个简码:

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' );}

Which shows the current stock level of the product ID and it works perfectly on desktop browsers but mobile browsers it only shows the max stock level all the time.它显示了产品 ID 的当前库存水平,它在桌面浏览器上完美运行,但在移动浏览器上它始终只显示最大库存水平。

It's simply used like this:它只是像这样使用:

[product_qty id='2329']

And every desktop browser, including the emulated mobile viewports in Chrome and Elementors responsive mode show it correctly.每个桌面浏览器,包括 Chrome 和 Elementors 响应模式中的模拟移动视口,都能正确显示。 Even on Chrome mobile, if you set it to desktop mode, the correct stock level is shown.即使在 Chrome 移动版上,如果将其设置为桌面模式,也会显示正确的库存水平。 It's only on native mobile browsers that it doesn't seem to work.它仅在本机移动浏览器上似乎不起作用。

Why might this be happening?为什么会这样?

Turns out it was a weird caching problem that was being caused by Siteground's Optimisation plugin.原来这是一个奇怪的缓存问题,是由 Siteground 的优化插件引起的。 I haven't figured out which if the three caching options is the cause yet, but I'll update this answer when I do.我还没有弄清楚这三个缓存选项是否是原因,但我会在我这样做时更新这个答案。

It was also preventing custom add to cart links from working, again only in mobile.它还阻止了自定义添加到购物车链接的工作,同样仅在移动设备中。 So a weird problem and one I'll be reporting to Siteground.这是一个奇怪的问题,我将向 Siteground 报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM