gpt4 book ai didi

php - 如何在 Woocommerce 订阅中设置下一个付款日期?

转载 作者:搜寻专家 更新时间:2023-10-31 20:35:20 24 4
gpt4 key购买 nike

我想在创建初始(第一个)订单后更改有效订阅的下一个付款日期。

当前代码不起作用。为什么?我错过了什么?

//fires when new order payment is complete (NOT RENEWAL but original order!)
add_action('woocommerce_payment_complete', 'fm_upate_next_payment_datetime');

function fm_upate_next_payment_datetime ( $order_id ) {

if (WC_Subscriptions_Order::order_contains_subscription( $order_id ) == false) return;
$subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order_id, $product_id
= '');

//hard code next payment date...(must be in future)
$next_payment = date( 'Y-m-d H:i:s', '2016-05-20 00:10:10' );

//set the new payment date
WC_Subscriptions_Manager::set_next_payment_date( $subscription_key, $user_id = '', $next_payment );

}

最佳答案

如您所说,我们还需要设定一个开始日期! (现在可以)但如果它没有通过,它将抛出一个错误。让它像这样工作:

function saveNewDate($post_id) {

$subscription = wcs_get_subscription( $post_id );
$dates = array();

$datetime = current_time( 'timestamp', true );
$dates[ 'start' ] = date( 'Y-m-d H:i:s', $datetime );
$datetime = strtotime( "08/23/2016 23:30" );
$dates['next_payment'] = date( 'Y-m-d H:i:s', $datetime );

try {
$subscription->update_dates( $dates, 'gmt' );
wp_cache_delete( $post_id, 'posts' );
} catch ( Exception $e ) {
wcs_add_admin_notice( $e->getMessage(), 'error' );
}
}

关于php - 如何在 Woocommerce 订阅中设置下一个付款日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37068851/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com