- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试更新所有产品销售价格的 wp_postmeta 表。
由于这两个字段都是 meta_key
/meta_value
对,所以我正在努力解决这个问题在此wp_postmeta 表中。
我如何编写一个查询来更新所有 '_sale_price' = 0 WHERE '_sale_price' > '_price'
?
最佳答案
使用自定义函数的不同方法应该可以完成相同的工作。您将不得不只使用一次,然后在工作完成后将其删除(在首次加载网站时,该过程将取决于您拥有的产品数量)。
代码如下:
function update_products_sale_price(){
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'post_status' => 'publish'
);
// getting all products
$products = get_posts( $args );
// Going through all products
foreach ( $products as $key => $value ) {
// the product ID
$product_id = $value->ID;
// Getting the product sale price
$sale_price = get_post_meta($product_id, '_sale_price', true);
// if product sale price is not defined we give to the variable a 0 value
if (empty($sale_price))
$sale_price = 0;
// Getting the product sale price
$price = get_post_meta($product_id, '_price', true);
// udate sale_price to 0 if sale price is bigger than price
if ($sale_price > $price)
update_post_meta($product_id, '_sale_price', '0');
}
}
// Here the function we will do the job.
update_products_sale_price();
你也可以将代码函数嵌入到一个钩子(Hook)中......
此代码位于您的事件子主题或主题的 function.php 文件中
此代码已经过测试且功能齐全
引用资料:
关于php - 如果 "sale_price"大于 "price",则更新所有 WooCommerce 产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38934249/
我想创建一个 sql 查询,为 2 个不同的查询一起返回结果。例如,我想要以下形式的结果:产品名称, avg(price), min(price), max(price), avg(order), m
我找不到 itemprop s 表示 schema.org 上有两种价格的产品。 价格类型有: 旧价 全新 Markdown 我无法想象,没有适合的 schema.org 标记,但经过长时间的搜索,我
我正在尝试更改 Magento 中的“特价”和“正常价格”措辞。我已经尝试编辑 Mage_Catalogue.csv、重新上传并清除缓存,但无济于事。我还在整个站点内对“常规”和“特殊”文本进行了巨大
考虑下表: sp100_id _date open close bullishness ----------------------------------------------
我试图显示某些产品变体的价格比较,但我不知道如何仅在大于零的变体的价格比较时显示它。它显示的是 0.00 美元价格的比较。 它使用 JavaScript 来动态更新价格。这是代码: 当我有一个原
我需要一些帮助来在 xml 中构建这一行。对于谷歌内容 API 我想要得到的结果是 25 目前我的代码输出这一行 25这是不正确的。 这是我的代码 b = Nokogiri::XML::Builder
我想在产品详细信息页面的价格框中显示带有名称的自定义选项价格。 我也试过这个链接但没有成功this is link i use 所以请给我建议任何解决方案。 最佳答案 首先你必须按下按钮 calcul
我想除以 {{ item.price |没有货币的货币 }} 提高 1.21。我正在隐藏输入值中调用 item.price。 When I do the below, it shows the va
因此,我想验证用户在文本字段中输入的价格: 条件(或限制): 值应始终大于零 值不能包含负号“-” 值不能多次包含小数点。还值不应以小数点开头 此外,我必须记住,这也应该适用于移动设备,因为该应用程
我使用分级价格,并对 1 到 4 之间的数量设定了固定价格,对超过 4 的数量设定了每件商品的价格。 我想修改我的购物车,为数量 >= 1 && 数量 <=4 的商品设置固定价格 我该怎么做? 这是我
Google In-app payment API 中有没有办法从应用中设置商品的价格? 我想在我的应用程序中创建一个捐赠我的应用程序按钮。会有一些预定义的捐赠金额(例如 1 美元、5 美元、10 美
我有一个数据库,其中有一列名为“价格” - 在此列中,价格四舍五入到小数点后 5 位,例如 62.083333 - 我想运行命令将“price”列中的每个值更改为仅 2 位小数,例如 62.08 是否
我的数据库中有一个名为“价格”的字段,它设置为 varchar。它包含美元符号和逗号。 我的数据库中的值是这样的: 100,000 美元 625,005 美元 115,990 美元 2,450,000
我有一个基本的 html 表单,它使用 PHP 向页面添加一些数据。我想使这个表单字段成为“价格”字段。我的 HTML 是: 如何修复此字段,以便用户无法输入随机字母、美元符号、破折号或其他奇怪的格
我试过这段代码,但没有给出解决方案。不使用引导表。我如何管理每项服务的点数。价格如何出现在适当的列中以及点数如何自动管理。 Title Rates
它们是一种将字符串格式化为 $ 价格的内置方式,例如12345.45 转换为 $12,345.45? 最佳答案 假设您使用的是 Cocoa(或只是 Foundation),您可以使用 NSNumber
我正在尝试获取 UniswapV2 上一对的价格:这是我的代码: pragma solidity ^0.5.1; import '@uniswap/v2-core/contracts/interfac
我正在寻找一种替代方法 template/catalog/product/price.phml在一个特定位置使用,并继续在所有其他位置使用现有的 price.phtml 文件。 为了进一步解释,我需要
我正在使用 VBScript(经典 ASP)和 SQL Server;我正在尝试在网站上设置一个部分,您可以在其中查看特定价格水平的产品数量。像这样的东西: $50 - $100 (4) $100 -
鉴于以下价格列表,我试图弄清楚如何仅规范化/提取数字。 INPUT DESIRED_OUTPUT CA$1399.00 1399.00 $1399.11 1399
我是一名优秀的程序员,十分优秀!