提交表单代码后出现严重错误-Woocommerce-重力

时间:2020-07-28 17:15:42

标签: wordpress woocommerce gravity-forms-plugin

我大约有3个重力形式,提交表单后,我的代码会使用提交的条目中的信息创建woocommerce订单。

在此阶段,它正在为我创建订单,但它会不断加载“您的网站上的严重错误”结果。

除了代码片段和Woocommerce外,我已停用所有插件,并更改了主题,但仍然收到相同的错误。

我想知道是否是因为案例之间的代码中断。当前是表格56引起了我的痛苦-尽管我最近还没有发现其他问题。

我希望有人可以在这里给我建议:

function post_to_third_party($entry, $form ) {

    switch ($form['id']) {

        case 56:
            
// set some variables
$user_id =rgar( $entry, '97' );
$product_id = rgar( $entry, '71' );
$quantity = rgar( $entry, '73' ); 
$price = rgar( $entry, '90' );
$note = rgar( $entry, '53' );

$product = wc_get_product($product_id);

// Set price
$product->set_price( $price );

$address = array(
    'first_name' => rgar( $entry, '98' ),
    'last_name' => rgar( $entry, '99' ), 
    'company' => rgar( $entry, '' ),
    'email' => rgar( $entry, '83' ), 
    'phone' => rgar( $entry, '84' ), 
    'address_1' => rgar( $entry, '88.1' ), 
    'address_2' => rgar( $entry, '88.2' ), 
    'city' => rgar( $entry, '88.3' ), 
    'state' => rgar( $entry, '88.4' ), 
    'postcode' => rgar( $entry, '88.5' ), 
    'country' => rgar( $entry, '88.6' ),
);

// Create the order object 
$order = wc_create_order();
$order->set_customer_id( $user_id );

// add product to order
$order->add_product( $product, $quantity );

foreach ($order->get_items() as $item_key => $item ) {
    $item->add_meta_data( 'Label', $note, true );
}

$order->set_address( $address, 'billing' );
$order->calculate_totals();
$order->update_status( 'pending payment', 'pending', TRUE); 

$order->add_order_note( $note );
$coupon_code = rgar( $entry, '105' );
$order->apply_coupon($coupon_code);  
        case 41:
            
$product_id = rgar( $entry, '16' );
$quantity = 1; 
$price = rgar( $entry, '11' );
$note = rgar( $entry, '22' );
$product = wc_get_product($product_id);
$imported_total_fee =rgar($entry,'21');
// Set price
$product->set_price( $price );

$address = array(
    'first_name' => rgar( $entry, '27' ),
    'last_name' => rgar( $entry, '28' ), 
    'email' => rgar( $entry, '24' ), 
    'phone' => rgar( $entry, '25' ), 
   'address_1' => rgar( $entry, '33.1' ), 
    'address_2' => rgar( $entry, '33.2' ), 
    'city' => rgar( $entry, '33.3' ), 
    'state' => rgar( $entry, '33.4' ), 
    'postcode' => rgar( $entry, '33.5' ), 
    'country' => rgar( $entry, '33.6' ),
);

// Create the order object 
$order = wc_create_order();
$order->set_customer_id( $user_id );

// add product to order
$order->add_product( $product, $quantity );

foreach ($order->get_items() as $item_key => $item ) {
    $item->add_meta_data( 'Note', $note, true );
}
$order->set_address( $address, 'billing' );
$order->set_address($address,'shipping');
        $country_code = $order->get_shipping_country();


// Set the array for tax calculations

$calculate_tax_for = array(
    'country' => ($country_code),
    'state' => '', // Can be set (optional)
    'postcode' => '', // Can be set (optional)
    'city' => '', // Can be set (optional)
);

// Optionally, set a total shipping amount
$new_ship_price = rgar($entry,'21');

// Get a new instance of the WC_Order_Item_Shipping Object
$item = new WC_Order_Item_Shipping();   
            $item->set_method_title( getenv('SHIPPING_TITLE') );
        $item->set_method_id( "flat_rate:1" ); // set an existing Shipping method rate ID
        $item->set_total( $new_ship_price ); // (optional)
        
        
        $order->add_item( $item );
$item->calculate_taxes($calculate_tax_for);
$order->calculate_totals();
$order->update_status( 'pending payment', 'pending', TRUE); 

$order->add_order_note( $note );
$order->save();



break;
                 case 90:
            // set some variables 

$product_id = rgar( $entry, '6' );
$quantity =1; 
$note = rgar( $entry, '{entry_id}' );
$product = wc_get_product($product_id); 
                                                                                                                        
$address = array( 'first_name' => rgar( $entry, '10' ), 'last_name' => rgar( $entry, '11' ),'email' => rgar( $entry, '9' ), );
                                                                                                                        
$order = wc_create_order(); $order->set_customer_id( $user_id ); $order->add_product( wc_get_product($product_id), $quantity, $prices); foreach ($order->get_items() as $item_key => $item ) { $item->add_meta_data( 'Booking Request', $note, true ); } $order->set_address( $address, 'billing' ); $order->calculate_totals(); $order->update_status( 'pending payment', 'pending', TRUE); $order->add_order_note( $note );
                                                                                    
                                                                                                                       
            break;
    
    }}

0 个答案:

没有答案