Woocommerce API order id (class-wc-order.php) - php

I needed to add some params to the order_data array in(v2/class-wc-api-order.php) woocommere and i've created a plugin so my changes wouldn't be overwritten by every update but i cant manage to get the id from the class?
I want $id to be the same the id i send in with my API
$id =
$order = wc_get_order( $id );
$olddata = array(
'first_name' => $order->shipping_first_name,
'last_name' => $order->shipping_last_name,
'company' => $order->shipping_company,
'address_1' => $order->shipping_address_1,
'address_2' => $order->shipping_address_2,
'city' => $order->shipping_city,
'state' => $order->shipping_state,
'postcode' => $order->shipping_postcode,
'country' => $order->shipping_country,
);

Related

Magento 1.9 Create Order From Cart via Skript

I try to create an order with item from cart.
I've found a skript that worked on ssh in magento root, but when I call the skript via checkout/cart->skript-php I got 500 Server Error.
My Skript is here:
<?php
require_once 'app/Mage.php';
Mage::app();
$quote = Mage::getModel('sales/quote')
->setStoreId(Mage::app()->getStore('default')->getId());
$product = Mage::getSingleton('checkout/cart')->getItems();
//$product = Mage::getModel('catalog/product')->load(87561); /* 6 => Some product ID */
$buyInfo = array('qty' => 1);
$quote->addProduct($product, new Varien_Object($buyInfo));
$billingAddress = array(
'firstname' => 'Me',
'lastname' => 'And',
'company' => 'None',
'email' => 'asdf#asdf.com',
'street' => array(
'Sample Street Line_1',
'Sample Street Line_2'
),
'city' => 'City',
'region_id' => '',
'region' => 'State/Province',
'postcode' => '12345',
'country_id' => 'DE',
'telephone' => '1234567890',
'fax' => '123456987',
'customer_password' => '',
'confirm_password' => '',
'save_in_address_book' => '0',
'use_for_shipping' => '1',
);
$quote->getBillingAddress()
->addData($billingAddress);
$quote->getShippingAddress()
->addData($billingAddress)
->setShippingMethod('solutioo')
->setPaymentMethod('cashondelivery')
->setCollectShippingRates(true)
->collectTotals();
$quote->setCheckoutMethod('guest')
->setCustomerId(null)
->setCustomerEmail($quote->getBillingAddress()->getEmail())
->setCustomerIsGuest(true)
->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
$quote->getPayment()->importData( array('method' => 'cashondelivery'));
$quote->save();
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
//$order = $service->getOrder();
2 Questions:
1- How should I call the skript from Magento Cart so it will work?
2- Is this the right way to get the product
Hope somebody can help me, ... Thanks in advance.

How do you add a new Line Item(non product)/Fee to a existing Order?

o/
Working on a minor project, and I'm creating a WC order from the admin area (programmatically), and i want to add a line item(Non product/fee to the order after it been created, but how exactly do i do that?
I create a order by doing:
$address = array(
'first_name' => $sBillingFirstName,
'last_name' => $sBillingLastName,
'company' => $sBillingCompanyName,
'email' => $sBillingEmail,
'phone' => $sBillingPhone,
'address_1' => $sBillingAddress1,
'address_2' => $sBillingAddress2,
'city' => $sBillingCity,
'state' => '',
'postcode' => $sBillingZipcode,
'country' => $sBillingCountry,
);
$oOrder = wc_create_order();
$oOrder->set_address( $address, 'billing' );
$oOrder->set_address( $address, 'shipping' );
and normally i would just do add_fee, as seen below to add a "non product" lineitem/fee, but since i dont have a cart object - what am i supposed to do?
wc->cart->add_fee("deposit", 200);
but i don't have a cart object, so how do i go about creating a the deposit in my new order?

How to add order delivery date and time in WooCommerce order?

Currently i am working on a REST API for place order and i have
created order using following code.
<?php
$order = wc_create_order(array('customer_id' => $user_id));
$billing_addre = array(
'first_name' => $_POST['f_name'],
'last_name' => $_POST['l_name'],
'company' => '',
'email' => $_POST['email'],
'phone' => $_POST['phone'],
'address_1' => $_POST['address'],
'address_2' => '',
'city' => $_POST['city'],
'state' => $_POST['state'],
'postcode' => $_POST['p_code'],
'country' => $_POST['country']
);
$order->set_address( $billing_addre, 'billing' );
?>
it's working good but i would like to add order delivery date and time
during create order, i added it by using custom field like
<?php
update_post_meta( $order->id, 'delivery_date', $_REQUEST["delivery_date"] );
?>
but that is no best way,( i don't do this by any plugin ) if anyone know better solution for this.
Thank You!

Codeigniter not espacing post data on insert

Trying to insert random emails like test''#test.com, etc.. and they are inserted into the database. Shouldn't this be automatically prevented by Active Record?
My query:
$data = array(
'name' => ''.$name.'' ,
'email' => ''.$email.'' ,
'country' => ''.$country.'' ,
'phone' => ''.$phone.'' ,
'compid' => ''.$compID.''
);
$this->db->insert('people', $data);
Where all variables are taken from user POST input, such as
$this->input->post('address')
for address.
shouldn't this be:
$data = array(
'name' => $name,
'email' => $email,
'country' => $country,
'phone' => $phone,
'compid' => $compID
);
$this->db->insert('people', $data);

wordpress new user meta key

I want to create a custom registration for wordpress and I need to create a new custom field for each profile. For example a phone field.
Here's my code
function registration()
{
$userdata = array(
'user_login' => esc_attr($this->username),
'phone' => esc_attr($this->username),
'pre_user_email' => esc_attr($this->email),
'user_pass' => esc_attr($this->password),
'user_url' => esc_attr($this->website),
'first_name' => esc_attr($this->first_name),
'last_name' => esc_attr($this->last_name),
'nickname' => esc_attr($this->nickname),
'description' => esc_attr($this->bio),
);
The phone line is my custom field for profile.
It doesn't work, I've tried creating a custom field in the admin user panel, and it works! But I can't insert data to that field phone
function registration()
{
$userdata = array(
'user_login' => esc_attr($this->username),
'phone' => esc_attr($this->phone),
'pre_user_email' => esc_attr($this->email),
'user_pass' => esc_attr($this->password),
'user_url' => esc_attr($this->website),
'first_name' => esc_attr($this->first_name),
'last_name' => esc_attr($this->last_name),
'nickname' => esc_attr($this->nickname),
'description' => esc_attr($this->bio),
);
}
You should add 'phone' string on MySQL db

Categories