WooCommerce にオンライン ストアがあり、次のオプションがあります。x 期間に達した場合、その注文のステータスをキャンセルに変更し、注文を送信する前の在庫を設定します。
x期間に達し、注文ステータスの変更が完了し、アイテムが在庫から削減された場合、それを変更したい.
私が知る限り、それは在庫を減らして注文をキャンセルするコードです.
/**
* woocommerce_cancel_unpaid_orders function.
*
* @access public
* @return void
*/
function woocommerce_cancel_unpaid_orders() {
global $wpdb;
$held_duration = get_option( 'woocommerce_hold_stock_minutes' );
if ( $held_duration < 1 || get_option( 'woocommerce_manage_stock' ) != 'yes' )
return;
$date = date( "Y-m-d H:i:s", strtotime( '-' . absint( $held_duration ) . ' MINUTES', current_time( 'timestamp' ) ) );
$unpaid_orders = $wpdb->get_col( $wpdb->prepare( "
SELECT posts.ID
FROM {$wpdb->posts} AS posts
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ('pending')
AND posts.post_modified < %s
", $date ) );
if ( $unpaid_orders ) {
foreach ( $unpaid_orders as $unpaid_order ) {
$order = new WC_Order( $unpaid_order );
if ( apply_filters( 'woocommerce_cancel_unpaid_order', true, $order ) )
$order->update_status( 'cancelled', __( 'Unpaid order cancelled - time limit reached.', 'woocommerce' ) );
}
}
wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' );
wp_schedule_single_event( time() + ( absint( $held_duration ) * 60 ), 'woocommerce_cancel_unpaid_orders' );
}
add_action( 'woocommerce_cancel_unpaid_orders', 'woocommerce_cancel_unpaid_orders' );
個人的に私はこの変更を行いましたが、意味がありますか?
/**
* woocommerce_cancel_unpaid_orders function.
*
* @access public
* @return void
*/
function woocommerce_cancel_unpaid_orders() {
global $wpdb;
$held_duration = get_option( 'woocommerce_hold_stock_minutes' );
if ( $held_duration < 1 || get_option( 'woocommerce_manage_stock' ) != 'yes' )
return;
$date = date( "Y-m-d H:i:s", strtotime( '-' . absint( $held_duration ) . ' MINUTES', current_time( 'timestamp' ) ) );
$unpaid_orders = $wpdb->get_col( $wpdb->prepare( "
SELECT posts.ID
FROM {$wpdb->posts} AS posts
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ('pending')
AND posts.post_modified < %s
", $date ) );
if ( $unpaid_orders ) {
foreach ( $unpaid_orders as $unpaid_order ) {
$order = new WC_Order( $unpaid_order );
if ( apply_filters( 'woocommerce_payment_complete_order_status', true, $order ) )
$order->update_status( 'completed', __( 'order completed - time limit reached.', 'woocommerce' ) );
}
}
wp_clear_scheduled_hook( 'woocommerce_payment_complete_order_status' );
wp_schedule_single_event( time() + ( absint( $held_duration ) * 60 ), 'woocommerce_payment_complete_order_status' );
}
add_action( 'woocommerce_payment_complete_order_status', 'woocommerce_payment_complete_order_status' );
このフィルター「woocommerce_cancel_unpaid_order」をこのwoocommerce_payment_complete_order_statusに置き換えました
$order->update_status( 'cancelled', __( '未払いの注文がキャンセルされました - 期限に達しました.', 'woocommerce' ) );
これで
$order->update_status( '完了', __( '注文完了 - 期限に達しました.', 'woocommerce' ) );
まだテストされていない bcz テストする前に確認が必要です。