WooCommerce用Javascript更新价格

时间:2018-06-11 15:54:40

标签: javascript jquery wordpress woocommerce

我想批量更新WooCommerce商店的促销价格(所有商品均可享受20%的折扣)。这个商店有很多产品变化,所以我期待用jQuery更新字段。

使用以下代码我已经能够更新字段并更新' wp_postmeta'的数据库表。 (_sale_price)。不幸的是,这还不够,因为' wp_options'中的序列化内容。 没有更新。为了更新,我仍然需要手动更改输入字段值。然后,它会触发更改并使用admin-ajax.php进行更新。

$('input[name^=variable_regular_price]').each(function(index) {
    var x = $(this).val();
    var y = $(this).closest('.variable_pricing').find('input[name^=variable_sale_price]');
    if (x) {
        x = x.replace(',','.');
        z = Number(x * 0.8).toFixed(2).replace('.', ',');
        y.val(z);
        y.trigger('change');
        y.trigger('blur');
        // I've tried all other variations of keydown, focus, etc
    }
});

如何使用Javascript更改输入字段的val(),以便在数据库中正确激活?

输入字段示例

<input type="text" class="short wc_input_price" style="" name="variable_sale_price[0]" id="variable_sale_price0" value="40,00" placeholder="">

类似问题

0 个答案:

没有答案