在Woocommerce中从数量输入字段中隐藏“数量”标签

时间:2019-02-04 13:49:06

标签: html css wordpress woocommerce product-quantity

我只是在我的functions.php文件中使用了一段代码来隐藏数量框-代码为:

def partition(num):
    """
    Return True if there exist primes x,y such that num = x + y.
    Else return False.
    """
    primelist = primes(num)
    for x in primelist:
        y= num-x
        # Note: num = x + y, thus need only check y prime
        if y in primelist:
            return True
    # If no such y is prime, not possible
    else:
        return False

def primes(num):
    """Return list of all primes less than num."""
    primelist=[]
    for i in range(2,num + 1):
        for p in range(2,i):
            if (i % p) == 0:
                break
        else:
            primelist.append(i)
    return primelist

现在,当我注释掉时,数量又回来了,但带有“数量”标签,这是以前从未有过的。

为什么会突然发生这种情况,以及如何隐藏标签?

enter image description here

1 个答案:

答案 0 :(得分:1)

为此数量字段生成的html输出应类似于:

<div class="quantity">
    <label class="screen-reader-text" for="quantity_5c5856feb38cb">Quantity</label>
    <input type="number" id="quantity_5c5856feb38cb" class="input-text qty text" step="1" min="1" max="35" name="quantity" value="1" title="Qty" size="4" pattern="[0-9]*" inputmode="numeric" aria-labelledby="Happy Ninja quantity">
</div>

因此,此数量字段的<label>标签使用screen-reader-text类通过以下CSS规则将其隐藏:

.screen-reader-text {
    border: 0;
    clip: rect(1px,1px,1px,1px);
    -webkit-clip-path: inset(50%);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal !important;
}

所以您已在某处进行了一些更改,这就是为什么“数量”标签可见的原因。


编辑:

因此,您可以尝试将以下CSS规则添加到活动主题的styles.css文件中:

.single-product div.quantity > label {
    display: block !important;
    border: 0;
    clip: rect(1px,1px,1px,1px);
    -webkit-clip-path: inset(50%);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px !important;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal !important;
}

它应该可以工作,并在单个产品页面上隐藏“数量”标签…

相关问题