【发布时间】:2020-11-23 04:31:20
【问题描述】:
我有 1 个订阅,包含 3 个变体。 我正在尝试根据购买的变体 ID 强制第一个续订日期。
变体 1 (876) 设置为每天更新 - 我希望第一个重新计费日期为 2020 年 11 月 15 日上午 12:00 变体 2 (877) 设置为每 2 天更新一次 - 我希望第一个重新计费日期为 2021 年 2 月 15 日上午 12:00 变体 3 (878) 设置为每 3 天更新一次 - 我希望第一个重新计费日期为 2021 年 8 月 15 日上午 12:00
我认为下面的代码有效。创建订单后,下一个账单日期会显示上述日期之一,但不能是在 WooCommerce 或其他地方注册,因为无论上述日期如何,都会触发续订。
对于我的测试,我为变体 1 创建了一个订单,下一个付款日期显示为 2020 年 11 月 15 日,但它会在第二天续订。
希望能从比我聪明的人那里得到一些见解。同样,潜艇的下一个账单日期显示上述日期,但续订仍会提前/在上述日期之前进行。
function nextpaymentdatechange( $order_id ){
$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item_id => $item ) {
$product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
if ( $product_id === 876 ) {
$subid = $order_id + 1;
$nextdate = get_post_meta( $subid, '_schedule_next_payment', true );
$new_date = date( 'Y-m-d H:i:s', strtotime( '2020-11-15 07:00:00', strtotime( $nextdate )) );
update_post_meta( $subid , '_schedule_next_payment', $new_date);
}
else{ if ( $product_id === 877 ) {
$subid = $order_id + 1;
$nextdate = get_post_meta( $subid, '_schedule_next_payment', true );
$new_date = date( 'Y-m-d H:i:s', strtotime( '2021-02-15 07:00:00', strtotime( $nextdate )) );
update_post_meta( $subid , '_schedule_next_payment', $new_date);
}
else{
if ( $product_id === 878 ) {
$subid = $order_id + 1;
$nextdate = get_post_meta( $subid, '_schedule_next_payment', true );
$new_date = date( 'Y-m-d H:i:s', strtotime( '2021-08-03 07:00:00', strtotime( $nextdate )) );
update_post_meta( $subid , '_schedule_next_payment', $new_date);
}
}
}
}
} ```
【问题讨论】:
-
你有解决这个问题的办法吗?
标签: php wordpress date woocommerce woocommerce-subscriptions