Get order error

Connect and get the answers to your API questions with advice from fellow developers.

Activity in Developer Groups

Sorted by:

IAF token supplied is invalid.

Hi,I keep getting:IAF token supplied is invalid.I have gotten a new token and am using SOAP server:https://api.sandbox.ebay.com/wsapiIS there a problem with the sandbox?Thank you,Marc

Unable to OAuth login in Sandbox Environment

Hi,It’s been working perfectly recently but all of a sudden today I am facing issues retrieving an access token using OAuth. When trying to login using my developer user account and after inputting the password I get redirected to the same page, but …

I can’t get user token

I can’t get user token when choose login I get the message «We ran into a problem. Please try again later.»

Terrible layout for mobile app

I have had dozens of messages now asking if I would be willing to post an item when postage was always an option. The problem is the terrible layout of the page. The “collection in person” option is written below in bold. The postage amount is writte…

Resolved! How can I search for sold items?

I want to search only Sold Items, but I don’t know how to do it. I’m using the «search» API and using the filter parameter doesn’t provide such an option.

How to get message sent by eBay API?

I understand that I can obtain member message via GetMemberMessage or GetMyMessage API. I can see message sent buy another user. But I can not tracking my message sent to user? How can i do ? If you have any idea, please give to me? Thanks!

Application access token for iOS

I’m trying to create an eBay iOS app for the seller, I have an issue with getting the user access token. I requested the Application access token API , but I got a 405 error and the message says «Unexpected error occurred, please contact resource pro…

createItemPriceMarkdownPromotion crashing

Hello, I’ve tried to use https://developer.ebay.com/api-docs/sell/marketing/resources/item_price_markdown/methods/createItemPriceMarkdownPromotion endpoint to create a markdown promotion for multiple listings in an automated way, but when I send a va…

(BAF.Error.3) Working on Sell Hub (manually), but not programmatically

(Note: I’m working in sandbox environment, and haven’t tried in production) The .csv example I’m using:Action(SiteID=US|Country=US|Currency=USD|Version=1193|CC=UTF-8),Category,Title,Subtitle,ConditionID,C:MPN,C:Brand,C:Model,PicURL,Description,Format…

Publish Offer API returns http status 500 in sandbox enviroment

I want to publish item in sandbox enviroment, but Publish Offer API failed due to status code 500.Details of the error is following, but I don’t have an idea where is wrong because it’s ambiguous.Does anyone have an idea why this error occurs? { «err…

WC_API_Orders{}WC 1.0

Хуки из класса

Использование

$WC_API_Orders = new WC_API_Orders();
// use class methods

Методы

  1. ERROR: no method name found on line «
  2. ERROR: no method name found on line «
  3. ERROR: no method name found on line «
  4. ERROR: no method name found on line «
  5. ERROR: no method name found on line «
  6. ERROR: no method name found on line «
  7. public array_keys( wc_get_order_statuses() )
  8. ERROR: no method name found on line `}`
  9. ERROR: no method name found on line «
  10. ERROR: no method name found on line «
  11. ERROR: no method name found on line «
  12. ERROR: no method name found on line «
  13. ERROR: no method name found on line «
  14. ERROR: no method name found on line «
  15. public delete_order( $id, $force = false )
  16. ERROR: no method name found on line «
  17. ERROR: no method name found on line «
  18. ERROR: no method name found on line «
  19. ERROR: no method name found on line «
  20. ERROR: no method name found on line «
  21. ERROR: no method name found on line «
  22. public edit_order( $id, $data )
  23. ERROR: no method name found on line «
  24. ERROR: no method name found on line «
  25. ERROR: no method name found on line «
  26. ERROR: no method name found on line «
  27. public get_billing_last_name()
  28. public get_order( $id, $fields = null )
  29. ERROR: no method name found on line «
  30. ERROR: no method name found on line «
  31. public get_order_notes( $id, $fields = null )
  32. ERROR: no method name found on line «
  33. ERROR: no method name found on line «
  34. ERROR: no method name found on line «
  35. ERROR: no method name found on line «
  36. ERROR: no method name found on line «
  37. ERROR: no method name found on line «
  38. public get_comment_meta( $note->comment_ID, ‘is_customer_note’, true )
  39. ERROR: no method name found on line `}`
  40. private get_order_subtotal( $order )
  41. public get_orders( $fields = null, $filter = array(), $status = null, $page = 1 )
  42. public get_orders_count( $status = null, $filter = array() )
  43. ERROR: no method name found on line `*/`
  44. public array()
  45. ERROR: no method name found on line «
  46. ERROR: no method name found on line «
  47. ERROR: no method name found on line «
  48. ERROR: no method name found on line «
  49. ERROR: no method name found on line «
  50. private query_orders( $args )
  51. ERROR: no method name found on line «
  52. ERROR: no method name found on line `# GET /orders`
  53. ERROR: no method name found on line `# GET /orders`
  54. public register_routes( $routes )
  55. ERROR: no method name found on line «
  56. ERROR: no method name found on line «
  57. ERROR: no method name found on line «
  58. ERROR: no method name found on line «
  59. ERROR: no method name found on line «
  60. ERROR: no method name found on line «
  61. ERROR: no method name found on line «
  62. ERROR: no method name found on line «
  63. ERROR: no method name found on line «
  64. ERROR: no method name found on line «
  65. ERROR: no method name found on line «
  66. ERROR: no method name found on line «
  67. ERROR: no method name found on line «
  68. ERROR: no method name found on line «
  69. ERROR: no method name found on line «
  70. ERROR: no method name found on line «


Код WC_API_Orders{} WC API Orders{}

WC 7.3.0

class WC_API_Orders extends WC_API_Resource {

	/** @var string $base the route base */
	protected $base = '/orders';

	/**
	 * Register the routes for this class
	 *
	 * GET /orders
	 * GET /orders/count
	 * GET|PUT /orders/<id>
	 * GET /orders/<id>/notes
	 *
	 * @since 2.1
	 * @param array $routes
	 * @return array
	 */
	public function register_routes( $routes ) {

		# GET /orders
		$routes[ $this->base ] = array(
			array( array( $this, 'get_orders' ),     WC_API_Server::READABLE ),
		);

		# GET /orders/count
		$routes[ $this->base . '/count' ] = array(
			array( array( $this, 'get_orders_count' ), WC_API_Server::READABLE ),
		);

		# GET|PUT /orders/<id>
		$routes[ $this->base . '/(?P<id>d+)' ] = array(
			array( array( $this, 'get_order' ),  WC_API_Server::READABLE ),
			array( array( $this, 'edit_order' ), WC_API_Server::EDITABLE | WC_API_Server::ACCEPT_DATA ),
		);

		# GET /orders/<id>/notes
		$routes[ $this->base . '/(?P<id>d+)/notes' ] = array(
			array( array( $this, 'get_order_notes' ), WC_API_Server::READABLE ),
		);

		return $routes;
	}

	/**
	 * Get all orders
	 *
	 * @since 2.1
	 * @param string $fields
	 * @param array $filter
	 * @param string $status
	 * @param int $page
	 * @return array
	 */
	public function get_orders( $fields = null, $filter = array(), $status = null, $page = 1 ) {

		if ( ! empty( $status ) ) {
			$filter['status'] = $status;
		}

		$filter['page'] = $page;

		$query = $this->query_orders( $filter );

		$orders = array();

		foreach ( $query->posts as $order_id ) {

			if ( ! $this->is_readable( $order_id ) ) {
				continue;
			}

			$orders[] = current( $this->get_order( $order_id, $fields ) );
		}

		$this->server->add_pagination_headers( $query );

		return array( 'orders' => $orders );
	}


	/**
	 * Get the order for the given ID
	 *
	 * @since 2.1
	 * @param int $id the order ID
	 * @param array $fields
	 * @return array|WP_Error
	 */
	public function get_order( $id, $fields = null ) {

		// ensure order ID is valid & user has permission to read
		$id = $this->validate_request( $id, 'shop_order', 'read' );

		if ( is_wp_error( $id ) ) {
			return $id;
		}

		$order      = wc_get_order( $id );
		$order_data = array(
			'id'                        => $order->get_id(),
			'order_number'              => $order->get_order_number(),
			'created_at'                => $this->server->format_datetime( $order->get_date_created() ? $order->get_date_created()->getTimestamp() : 0, false, false ), // API gives UTC times.
			'updated_at'                => $this->server->format_datetime( $order->get_date_modified() ? $order->get_date_modified()->getTimestamp() : 0, false, false ), // API gives UTC times.
			'completed_at'              => $this->server->format_datetime( $order->get_date_completed() ? $order->get_date_completed()->getTimestamp() : 0, false, false ), // API gives UTC times.
			'status'                    => $order->get_status(),
			'currency'                  => $order->get_currency(),
			'total'                     => wc_format_decimal( $order->get_total(), 2 ),
			'subtotal'                  => wc_format_decimal( $this->get_order_subtotal( $order ), 2 ),
			'total_line_items_quantity' => $order->get_item_count(),
			'total_tax'                 => wc_format_decimal( $order->get_total_tax(), 2 ),
			'total_shipping'            => wc_format_decimal( $order->get_shipping_total(), 2 ),
			'cart_tax'                  => wc_format_decimal( $order->get_cart_tax(), 2 ),
			'shipping_tax'              => wc_format_decimal( $order->get_shipping_tax(), 2 ),
			'total_discount'            => wc_format_decimal( $order->get_total_discount(), 2 ),
			'cart_discount'             => wc_format_decimal( 0, 2 ),
			'order_discount'            => wc_format_decimal( 0, 2 ),
			'shipping_methods'          => $order->get_shipping_method(),
			'payment_details' => array(
				'method_id'    => $order->get_payment_method(),
				'method_title' => $order->get_payment_method_title(),
				'paid'         => ! is_null( $order->get_date_paid() ),
			),
			'billing_address' => array(
				'first_name' => $order->get_billing_first_name(),
				'last_name'  => $order->get_billing_last_name(),
				'company'    => $order->get_billing_company(),
				'address_1'  => $order->get_billing_address_1(),
				'address_2'  => $order->get_billing_address_2(),
				'city'       => $order->get_billing_city(),
				'state'      => $order->get_billing_state(),
				'postcode'   => $order->get_billing_postcode(),
				'country'    => $order->get_billing_country(),
				'email'      => $order->get_billing_email(),
				'phone'      => $order->get_billing_phone(),
			),
			'shipping_address' => array(
				'first_name' => $order->get_shipping_first_name(),
				'last_name'  => $order->get_shipping_last_name(),
				'company'    => $order->get_shipping_company(),
				'address_1'  => $order->get_shipping_address_1(),
				'address_2'  => $order->get_shipping_address_2(),
				'city'       => $order->get_shipping_city(),
				'state'      => $order->get_shipping_state(),
				'postcode'   => $order->get_shipping_postcode(),
				'country'    => $order->get_shipping_country(),
			),
			'note'                      => $order->get_customer_note(),
			'customer_ip'               => $order->get_customer_ip_address(),
			'customer_user_agent'       => $order->get_customer_user_agent(),
			'customer_id'               => $order->get_user_id(),
			'view_order_url'            => $order->get_view_order_url(),
			'line_items'                => array(),
			'shipping_lines'            => array(),
			'tax_lines'                 => array(),
			'fee_lines'                 => array(),
			'coupon_lines'              => array(),
		);

		// add line items
		foreach ( $order->get_items() as $item_id => $item ) {
			$product                    = $item->get_product();
			$order_data['line_items'][] = array(
				'id'         => $item_id,
				'subtotal'   => wc_format_decimal( $order->get_line_subtotal( $item ), 2 ),
				'total'      => wc_format_decimal( $order->get_line_total( $item ), 2 ),
				'total_tax'  => wc_format_decimal( $order->get_line_tax( $item ), 2 ),
				'price'      => wc_format_decimal( $order->get_item_total( $item ), 2 ),
				'quantity'   => $item->get_quantity(),
				'tax_class'  => $item->get_tax_class(),
				'name'       => $item->get_name(),
				'product_id' => $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id(),
				'sku'        => is_object( $product ) ? $product->get_sku() : null,
			);
		}

		// add shipping
		foreach ( $order->get_shipping_methods() as $shipping_item_id => $shipping_item ) {
			$order_data['shipping_lines'][] = array(
				'id'           => $shipping_item_id,
				'method_id'    => $shipping_item->get_method_id(),
				'method_title' => $shipping_item->get_name(),
				'total'        => wc_format_decimal( $shipping_item->get_total(), 2 ),
			);
		}

		// add taxes
		foreach ( $order->get_tax_totals() as $tax_code => $tax ) {
			$order_data['tax_lines'][] = array(
				'code'     => $tax_code,
				'title'    => $tax->label,
				'total'    => wc_format_decimal( $tax->amount, 2 ),
				'compound' => (bool) $tax->is_compound,
			);
		}

		// add fees
		foreach ( $order->get_fees() as $fee_item_id => $fee_item ) {
			$order_data['fee_lines'][] = array(
				'id'        => $fee_item_id,
				'title'     => $fee_item->get_name(),
				'tax_class' => $fee_item->get_tax_class(),
				'total'     => wc_format_decimal( $order->get_line_total( $fee_item ), 2 ),
				'total_tax' => wc_format_decimal( $order->get_line_tax( $fee_item ), 2 ),
			);
		}

		// add coupons
		foreach ( $order->get_items( 'coupon' ) as $coupon_item_id => $coupon_item ) {
			$order_data['coupon_lines'][] = array(
				'id'     => $coupon_item_id,
				'code'   => $coupon_item->get_code(),
				'amount' => wc_format_decimal( $coupon_item->get_discount(), 2 ),
			);
		}

		return array( 'order' => apply_filters( 'woocommerce_api_order_response', $order_data, $order, $fields, $this->server ) );
	}

	/**
	 * Get the total number of orders
	 *
	 * @since 2.1
	 *
	 * @param string $status
	 * @param array $filter
	 *
	 * @return array|WP_Error
	 */
	public function get_orders_count( $status = null, $filter = array() ) {

		if ( ! empty( $status ) ) {
			$filter['status'] = $status;
		}

		$query = $this->query_orders( $filter );

		if ( ! current_user_can( 'read_private_shop_orders' ) ) {
			return new WP_Error( 'woocommerce_api_user_cannot_read_orders_count', __( 'You do not have permission to read the orders count', 'woocommerce' ), array( 'status' => 401 ) );
		}

		return array( 'count' => (int) $query->found_posts );
	}

	/**
	 * Edit an order
	 *
	 * API v1 only allows updating the status of an order
	 *
	 * @since 2.1
	 * @param int $id the order ID
	 * @param array $data
	 * @return array|WP_Error
	 */
	public function edit_order( $id, $data ) {

		$id = $this->validate_request( $id, 'shop_order', 'edit' );

		if ( is_wp_error( $id ) ) {
			return $id;
		}

		$order = wc_get_order( $id );

		if ( ! empty( $data['status'] ) ) {

			$order->update_status( $data['status'], isset( $data['note'] ) ? $data['note'] : '' );
		}

		return $this->get_order( $id );
	}

	/**
	 * Delete an order
	 *
	 * @param int $id the order ID
	 * @param bool $force true to permanently delete order, false to move to trash
	 * @return array
	 */
	public function delete_order( $id, $force = false ) {

		$id = $this->validate_request( $id, 'shop_order', 'delete' );

		return $this->delete( $id, 'order',  ( 'true' === $force ) );
	}

	/**
	 * Get the admin order notes for an order
	 *
	 * @since 2.1
	 * @param int $id the order ID
	 * @param string $fields fields to include in response
	 * @return array|WP_Error
	 */
	public function get_order_notes( $id, $fields = null ) {

		// ensure ID is valid order ID
		$id = $this->validate_request( $id, 'shop_order', 'read' );

		if ( is_wp_error( $id ) ) {
			return $id;
		}

		$args = array(
			'post_id' => $id,
			'approve' => 'approve',
			'type'    => 'order_note',
		);

		remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );

		$notes = get_comments( $args );

		add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );

		$order_notes = array();

		foreach ( $notes as $note ) {

			$order_notes[] = array(
				'id'            => $note->comment_ID,
				'created_at'    => $this->server->format_datetime( $note->comment_date_gmt ),
				'note'          => $note->comment_content,
				'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ),
			);
		}

		return array( 'order_notes' => apply_filters( 'woocommerce_api_order_notes_response', $order_notes, $id, $fields, $notes, $this->server ) );
	}

	/**
	 * Helper method to get order post objects
	 *
	 * @since 2.1
	 * @param array $args request arguments for filtering query
	 * @return WP_Query
	 */
	private function query_orders( $args ) {

		// set base query arguments
		$query_args = array(
			'fields'      => 'ids',
			'post_type'   => 'shop_order',
			'post_status' => array_keys( wc_get_order_statuses() ),
		);

		// add status argument
		if ( ! empty( $args['status'] ) ) {

			$statuses                  = 'wc-' . str_replace( ',', ',wc-', $args['status'] );
			$statuses                  = explode( ',', $statuses );
			$query_args['post_status'] = $statuses;

			unset( $args['status'] );

		}

		$query_args = $this->merge_query_args( $query_args, $args );

		return new WP_Query( $query_args );
	}

	/**
	 * Helper method to get the order subtotal
	 *
	 * @since 2.1
	 * @param WC_Order $order
	 * @return float
	 */
	private function get_order_subtotal( $order ) {
		$subtotal = 0;

		// subtotal
		foreach ( $order->get_items() as $item ) {
			$subtotal += $item->get_subtotal();
		}

		return $subtotal;
	}
}

I developed a custom payment gateway plugin for a client, who wanted to add a similar method to “cod” (cash on delivery). FYI, he wanted to add a method called “card on delivery”. I simply duplicated the code, added the PHP to a file, made a plugin and gave him the plugin zip file. And everything was working great… until he did a test checkout.

The error that showed after placing an order

Fatal error: Call to undefined function wc_get_order() in /home/XXXXXXX/public_html/wp-content/plugins/woocommerce-gateway-carddelivery-plugin/woocommerce-gateway-carddelivery-plugin.php on line 201

The fix: wc_get_order() is only valid for WooCommerce 2.2+

It was very simple. The client was still using WooCommerce 2.1, where new orders are called differently. From WooCommerce 2.2, orders are created with wc_get_order() instead.

I simply substituted this:

$order = wc_get_order( $order_id );

with this:

$order = new WC_Order( $order_id );

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete «?>» if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files — if you need more guidance, please take a look at my free video tutorial «Where to Place WooCommerce Customization?»

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

Follow @rmelogli

Join 75,000+ Monthly Readers & 16,500+ Subscribers.

Become a Business Bloomer Supporter.

Join BloomerArmada and become an Official Business Bloomer Supporter:
easy-peasy, and lots of perks for you.

See your Benefits →

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Geolocation error user denied geolocation
  • Generic id error kess v2
  • Generic host process for win32 services обнаружена ошибка windows xp
  • Google chrome error connection reset
  • Google apps device policy ошибка сети

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии