Created
July 11, 2022 13:54
-
-
Save dgaitan/56f87ecd9c111deaa677240d60a85851 to your computer and use it in GitHub Desktop.
WordPress Order Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Retrieving a simple order | |
$order = wc_get_order( 1234 ); | |
// Then we can get info related to this order by running. | |
$order->get_id(); | |
$order->get_total() | |
// Also we could retrieve a collection of orders by running. | |
$orders = wc_get_orders( array( 'limit' => 10 ) ); | |
foreach ( $orders as $order ) { | |
$order->get_id(); | |
$order->get_shipping_method(); | |
$order->get_meta( 'my_custom_meta' ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Info about the order | |
$order->get_id(); | |
$order->get_order_key(); | |
$order->get_status(); | |
$order->get_checkout_order_received_url(); | |
$order->get_checkout_payment_url(); | |
$order->get_checkout_order_received_url(); | |
$order->get_cancel_order_url(); | |
$order->get_cancel_order_url_raw(); | |
$order->get_cancel_endpoint(); | |
$order->get_view_order_url(); | |
$order->get_edit_order_url(); | |
// Customer info | |
$order->get_customer_id(); | |
$order->get_user_id(); | |
$order->get_user(); | |
$order->get_customer_ip_address(); | |
$order->get_customer_user_agent(); | |
$order->get_created_via(); | |
$order->get_customer_note(); | |
// Shipping info | |
$order->get_shipping_method(); | |
$order->get_shipping_methods(); | |
$order->get_shipping_to_display(); | |
// Info related to payment | |
$order->get_payment_method(); | |
$order->get_payment_method_title(); | |
$order->get_transaction_id(); | |
// Get order totals | |
$order->get_formatted_order_total(); | |
$order->get_cart_tax(); | |
$order->get_currency(); | |
$order->get_discount_tax(); | |
$order->get_discount_to_display(); | |
$order->get_discount_total(); | |
$order->get_fees(); | |
$order->get_formatted_line_subtotal(); | |
$order->get_shipping_tax(); | |
$order->get_shipping_total(); | |
$order->get_subtotal(); | |
$order->get_subtotal_to_display(); | |
$order->get_tax_location(); | |
$order->get_tax_totals(); | |
$order->get_taxes(); | |
$order->get_total(); | |
$order->get_total_discount(); | |
$order->get_total_tax(); | |
$order->get_total_refunded(); | |
$order->get_total_tax_refunded(); | |
$order->get_total_shipping_refunded(); | |
$order->get_item_count_refunded(); | |
$order->get_total_qty_refunded(); | |
$order->get_qty_refunded_for_item(); | |
$order->get_total_refunded_for_item(); | |
$order->get_tax_refunded_for_item(); | |
$order->get_total_tax_refunded_by_rate_id(); | |
$order->get_remaining_refund_amount(); | |
// Get and loop items | |
foreach ( $order->get_items() as $item_id => $item ) { | |
$product_id = $item->get_product_id(); | |
$variation_id = $item->get_variation_id(); | |
$product = $item->get_product(); // it retrieves the WC_Product object related to this. | |
$product_name = $item->get_name(); | |
$quantity = $item->get_quantity(); | |
$subtotal = $item->get_subtotal(); | |
$total = $item->get_total(); | |
$tax = $item->get_subtotal_tax(); | |
$tax_class = $item->get_tax_class(); | |
$tax_status = $item->get_tax_status(); | |
$allmeta = $item->get_meta_data(); | |
$somemeta = $item->get_meta( '_my_item_meta_if_exists', true ); | |
$item_type = $item->get_type(); | |
} | |
// Secondary stuff | |
$order->get_items_key(); | |
$order->get_items_tax_classes(); | |
$order->get_item_count(); | |
$order->get_item_total(); | |
$order->get_downloadable_items(); | |
$order->get_coupon_codes(); | |
// Total related to the lines | |
$order->get_line_subtotal(); | |
$order->get_line_tax(); | |
$order->get_line_total(); | |
// Order dates | |
$order->get_date_created(); | |
$order->get_date_modified(); | |
$order->get_date_completed(); | |
$order->get_date_paid(); | |
// Billing & Shipping Address | |
$order->get_address_prop(); | |
$order->get_billing_first_name(); | |
$order->get_billing_last_name(); | |
$order->get_billing_company(); | |
$order->get_billing_address_1(); | |
$order->get_billing_address_2(); | |
$order->get_billing_city(); | |
$order->get_billing_state(); | |
$order->get_billing_postcode(); | |
$order->get_billing_country(); | |
$order->get_billing_email(); | |
$order->get_billing_phone(); | |
$order->get_shipping_first_name(); | |
$order->get_shipping_last_name(); | |
$order->get_shipping_company(); | |
$order->get_shipping_address_1(); | |
$order->get_shipping_address_2(); | |
$order->get_shipping_city(); | |
$order->get_shipping_state(); | |
$order->get_shipping_postcode(); | |
$order->get_shipping_country(); | |
$order->get_address(); | |
$order->get_shipping_address_map_url(); | |
$order->get_formatted_billing_full_name(); | |
$order->get_formatted_shipping_full_name(); | |
$order->get_formatted_billing_address(); | |
$order->get_formatted_shipping_address(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment