同じ作業を行う必要があるカスタム関数を使用する別の方法です。この機能をで1回だけにしてから、ジョブが終了した後に削除する必要があります(最初のサイトロード時には、プロセスは所有している製品の数によって異なります)。ここで
はコードです:あなたはまた、フックのコードの機能を埋め込むことができます
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();
...
このコードは、あなたのアクティブな子テーマやテーマ
のfunction.phpファイルに行きます
このコードはテスト済みで、完全に機能します。
参考文献:
'update_post_meta( 'product_idを'、 '_sale_price'、 '0');'この行は次のようになります。 'update_post_meta( '$のPRODUCT_IDを' 、 '_sale_price'、 '0'); '$ product_id変数を使用していますか? – MikeF
@MikeFああ確かに、小さな間違い...私はこれを正す。ありがとう。このコードは一度これを修正したのですか? – LoicTheAztec
そうでした。私はそれに少し調整を加えました。販売価格が価格よりも高い場合は、対応するpost_id列のmeta_key/meta_valueペアの削除クエリを実行するように設定しました。そうすれば、ウーマンコマースはそれを表示しません。ご協力いただきありがとうございます。大変感謝しております。 – MikeF