繁体   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