建立訂單中 - 豪樂適拇趾外翻矯正器-德國原裝

建立訂單中

[insert_php]

foreach ($_POST as $key => $value) {
echo ”
“; echo “”;
echo $key;
echo “”;
echo “”;
echo $value;
echo “”;
echo “”;
}$address = array(
‘first_name’ => $_POST[‘billing_last_name’],
‘last_name’ => $_POST[‘billing_last_name’],
’email’ => $_POST[‘billing_email’],
‘phone’ => $_POST[‘billing_phone’],
‘address_1’ => $_POST[‘billing_address_1’],
‘postcode’ => $_POST[‘postCode’]
);
global $woocommerce;
$items = $woocommerce->cart->get_cart();
$qty = array_values($items)[0][‘quantity’];
$name = ‘折扣’;

if ($qty >=2)
{
$amount = -200*$qty;
}
else
{
$amount = 0;
}
$fee = (object)array(
‘name’ => $name,
‘amount’ => $amount,
‘tax_data’ => array() // gets rid of “Warning: array_map(): Argument #2 should be an array”
);
$order = wc_create_order();
$order->add_product( get_product( 848 ), $qty );
$order->set_address( $address, ‘billing’ );
$order->set_address( $address, ‘shipping’ );
$order->add_fee($fee);
//$order->set_total(4200,’total’);
$order->calculate_totals();
update_post_meta( $order->id, ‘_payment_method’, ‘spgateway’ );

// Store Order ID in session so it can be re-used after payment failure
//WC()->cart->empty_cart();

WC()->session->order_awaiting_payment = $order->id;

// Process Payment
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
if ($_POST[‘method’] == ‘信用卡刷卡’)
{
$result = $available_gateways[ ‘spgateway’ ]->process_payment( $order->id );
if ( $result[‘result’] == ‘success’ ) {
$result = apply_filters( ‘woocommerce_payment_successful_result’, $result, $order->id );
wp_redirect( $result[‘redirect’] );
exit;
}
}
else
{
if ($qty >=2)
{
$order->payment_complete();
}
}
[/insert_php]

目前共有15人在瀏覽本產品