0

这个问题的目标是找到任何东西,通过它可以识别 ID 或任何东西,通过它可以跟踪正在编辑或更新所有产品价格的功能(最好是通过它的名称/slug) (假设是 1,25 倍),它们是由 cron 自动导入到商店的)。

每次函数更新产品时,它可以例如在某个地方存储该给定函数最后一次编辑产品的值。

到目前为止,我已经搜索了一些选项,我发现的选项如下:

1) get_the_author_meta("display_name"); 2) get_the_modified_author();

但是,这些选项都没有用,或者我根本没有设法让它们回响任何东西。

预期结果是:

1)找到一种方法如何通过留下跟踪或 ID 来跟踪更新帖子(产品)的功能,这将记录执行最后一次编辑的给定功能。

2) 找到一种方法来识别每个帖子中新创建的跟踪,并能够将其与其他功能一起使用。

最终目标是:确保当一个功能通过时,假设有 4000 个产品并且该功能由于某些外部原因而没有完成 - 它不会从一开始就再次通过,而只更改它尚未更改的产品.

如果该过程未完成,则该功能将由 cron 从一开始就重新启动(直到它完成) - 这目前会导致问题 - 因为已经更新的产品价格因子 1,25 正在再次更新相同因素。

有人有什么想法吗?

代码:

private function set_custom_price($product) {
    if (!$product->exists()) {
        return false;
    }

    $product_price = $product->get_regular_price();

    if (($product_price > 0) && ($product_price < 401)) {
        $product->set_regular_price(ceil(($product_price + ($product_price*(0.5)))/10) *10-1);
    } elseif (($product_price > 400) && ($product_price < 801)) {
        $product->set_regular_price(ceil(($product_price + 120)/10) *10-1);
    } elseif (($product_price > 800) && ($product_price < 1101)) {
        $product->set_regular_price(ceil(($product_price + 150)/10) *10-1);
    } elseif (($product_price > 1100) && ($product_price < 1601)) {
        $product->set_regular_price(ceil(($product_price + 200)/10) *10-1);
    } elseif (($product_price > 1600) && ($product_price < 2001)) {
        $product->set_regular_price(ceil(($product_price + 220)/10) *10-1);
    } elseif (($product_price > 2000) && ($product_price < 5001)) {
        $product->set_regular_price(ceil(($product_price + ($product_price*(0.15)))/10) *10-1);
    }

    $product->save();
    // HERE SOME CODE NEEDED TO REGISTER TRACE??
}
4

1 回答 1

0

你可能会使用这样的东西:

$product_id = $product->ID;
$last_changed = get_post_meta( $product_id, 'custom_product_last_change', true );
$last_changed_timestamp = strtotime($last_changed);
$current_datetime = strtotime(date('m/d/Y h:i:s a', time()));

// Check if change date is in last 24 hours ( you can change that to what ever you want, last week, last month..etc )
if($last_changed_timestamp > $current_datetime - 86400){

    update_post_meta( $product_id, 'custom_product_last_change', date('m/d/Y h:i:s a', time()) );
    // Do the changes here
}
于 2019-08-15T13:42:43.063 回答