Skip to content

Commit

Permalink
feat: 新增付款方式時,也要記錄暫存訂單的付款方式
Browse files Browse the repository at this point in the history
  • Loading branch information
j7-dev committed Jul 29, 2024
1 parent f1c535f commit 9c17ec7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion admin/card-management/class-card-management.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ private function get_order_by_post( $post ) {

$subscription_id = (int) $post->ID;
$subscription = \wcs_get_subscription( $subscription_id );
return $subscription->get_parent();
if ($subscription) {
return $subscription->get_parent();
}
return null;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions includes/payuni/src/gateways/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ public function add_payment_method(): array {
*/
$order = \wc_create_order();
$order->set_customer_id( \get_current_user_id() );
$order->set_payment_method( $this->id );
$order->set_payment_method_title( $this->get_title() );

// create Fee object.
$fee = new \WC_Order_Item_Fee();
Expand Down
6 changes: 4 additions & 2 deletions includes/payuni/src/pages/MyAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public function update_credit_hash( int $token_id, \WC_PAYMENT_TOKEN_CC $token )
foreach ( $subscriptions as $subscription ) {
$subscription_id = $subscription->get_id();
$subscription->set_payment_method( $gateway_id );
\update_post_meta( $subscription_id, '_payment_method', $gateway_id );
\update_post_meta( $subscription_id, '_payment_method_title', $payment_gateway_title );
$subscription->set_payment_method_title( $payment_gateway_title );
$subscription->save();

// 取得父訂單ID.
$parent_id = \wp_get_post_parent_id( $subscription_id );
Expand All @@ -117,6 +117,8 @@ public function update_credit_hash( int $token_id, \WC_PAYMENT_TOKEN_CC $token )
if ( ! $order ) {
continue;
}
$order->set_payment_method( $gateway_id );
$order->set_payment_method_title( $payment_gateway_title );
$order->update_meta_data( '_payuni_card_hash', $token->get_token() );
$order->update_meta_data( '_payuni_card_number', $token->get_last4() );
$order->update_meta_data( '_payuni_resp_card_bank', '不確定' );
Expand Down

0 comments on commit 9c17ec7

Please sign in to comment.