ID; $enabled = 'yes' === get_post_meta( $pid, '_mnbtwp_enabled', true ); $provider = (int) get_post_meta( $pid, '_mnbtwp_provider_id', true ); $webdx = (int) get_post_meta( $pid, '_mnbtwp_webdx', true ); $sqldx = (int) get_post_meta( $pid, '_mnbtwp_sqldx', true ); $flow = (int) get_post_meta( $pid, '_mnbtwp_ll', true ); $ymbds = (int) get_post_meta( $pid, '_mnbtwp_ymbds', true ); $months = (int) get_post_meta( $pid, '_mnbtwp_period_months', true ) ?: 12; global $wpdb; $providers = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}mnbt_providers WHERE qk='true' ORDER BY id ASC", ARRAY_A ); echo '
'; // 当启用开关变化时显隐字段。 ?> add_order_note( 'MNBT 处理失败:' . $e->getMessage() ); } } /** * 创建续费订单(含原商品 + 续费 meta),返回订单对象。 * * @param int $host_id 主机 ID。 * @param int $months 续费月数。 * @return \WC_Order * * @throws \Exception 原商品/订单缺失时抛出。 */ public static function create_renew_order( $host_id, $months ) { $host = Helpers::get_host( $host_id ); if ( ! $host ) { throw new \Exception( __( '主机不存在', 'wp-seller-plugin' ) ); } $months = max( 1, (int) $months ); $order = $host['order_id'] ? wc_get_order( (int) $host['order_id'] ) : null; $product_id = 0; if ( $order ) { foreach ( $order->get_items() as $item ) { $pid = (int) $item->get_product_id(); if ( 'yes' === get_post_meta( $pid, '_mnbtwp_enabled', true ) ) { $product_id = $pid; break; } } } if ( ! $product_id ) { throw new \Exception( __( '找不到原主机商品', 'wp-seller-plugin' ) ); } $product = wc_get_product( $product_id ); if ( ! $product ) { throw new \Exception( __( '原商品不存在', 'wp-seller-plugin' ) ); } $order = wc_create_order( array( 'customer_id' => (int) $host['user_id'] ) ); $order->add_product( $product, $months ); $order->add_meta_data( '_mnbtwp_renew_host_id', (int) $host_id ); $order->add_meta_data( '_mnbtwp_renew_months', $months ); $order->set_status( 'pending' ); $order->calculate_totals(); $order->save(); return $order; } }