WooCommerce: dostaň všechny data objednávky

Získání objektu s daty objednávky

// Získání $order objektu z ID objednávky
$order = wc_get_order( $order_id );

// Získání $order objektu v e-mailu
$order = $email->object;

Id objednávky

// Získání ID objednávky
$order->get_id();

// Získání unikátního klíče objednávky
$order->get_order_key();

Získání hodnot objednávky

$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();

Získání položek v objednávce

foreach ( $order->get_items() as $item_id => $item ) {
   $id_produktu  = $item->get_product_id();
   $id_varianty  = $item->get_variation_id();
   $produkt      = $item->get_product();
   $nazev_produktu = $item->get_name();
   $mnozstvi     = $item->get_quantity();
   $mezisoucet   = $item->get_subtotal();
   $celkova_cena = $item->get_total();
   $soucet_dane  = $item->get_subtotal_tax();
   $danova_trida = $item->get_tax_class();
   $status_dane  = $item->get_tax_status();
   $vsechny_meta = $item->get_meta_data();
   $vybrane_meta = $item->get_meta( 'meta_key', true );
   $product_type = $item->get_type();
}
$order->get_items_key();
$order->get_items_tax_classes();
$order->get_item_count();
$order->get_item_total();
$order->get_downloadable_items();

Hodnoty řádku

$order->get_line_subtotal();
$order->get_line_tax();
$order->get_line_total();

Doprava

$order->get_shipping_method();
$order->get_shipping_methods();
$order->get_shipping_to_display();

// Podmínka pro vybranou dopravu
if( $order->has_shipping_method('flat_rate') ){}

foreach( $order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ){
    $order_item_name             = $shipping_item_obj->get_name();
    $order_item_type             = $shipping_item_obj->get_type();
    $shipping_method_title       = $shipping_item_obj->get_method_title();
    $shipping_method_id          = $shipping_item_obj->get_method_id(); // The method ID
    $shipping_method_instance_id = $shipping_item_obj->get_instance_id(); // The instance ID
    $shipping_method_total       = $shipping_item_obj->get_total();
    $shipping_method_total_tax   = $shipping_item_obj->get_total_tax();
    $shipping_method_taxes       = $shipping_item_obj->get_taxes();
}
  

Poplatky

foreach( $the_order->get_items('fee') as $item_id => $item_fee ){

    // Jméno poplatku
    $fee_name = $item_fee->get_name();

    // Hodnota poplatku
    $fee_total = $item_fee->get_total();

    // Hodnota daně poplatku
    $fee_total_tax = $item_fee->get_total_tax();

    // Zobrazení celkové ceny formátované jako měna
    echo wc_price( $fee_total + $fee_total_tax);

    // Loop pro tabulku v order-details.php
    ?>
    <tr class="fee">
		<th colspan="2"><?php echo esc_html( $item_fee->get_name() ); ?></th>
		<td><?php echo wc_price( $fee_total + $fee_total_tax); ?></td>
	</tr>
    <?php
}
  

Datumy

$order->get_date_created();
$order->get_date_modified();
$order->get_date_completed();
$order->get_date_paid();

Zákazník, fakturační a doručovací adresy

$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();
$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();

Detaily platby

$order->get_payment_method();
$order->get_payment_method_title();
$order->get_transaction_id();

Odkazy objednávky

$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();

Stav objednávky

$order->get_status();

Kupóny

$order->get_coupon_codes();

foreach( $order->get_coupon_codes() as $coupon_code ) {
    $coupon = new WC_Coupon($coupon_code); // Načtěte objekt kupónu
    $discount_type = $coupon->get_discount_type(); // Typ slevy
    $coupon_amount = $coupon->get_amount(); // Hodnota kupónu
}
<?php 
// Custom zobrazení v order-details.php
foreach ( $order->get_items('coupon') as $code => $coupon ) { ?>
	<tr class="cart-discount coupon-<?php echo esc_attr( sanitize_title( $code ) ); ?>">
		<th colspan="2"><?php wc_cart_totals_coupon_label( $coupon ); ?></th>				
		<td>-<?php echo wc_price( wc_get_order_item_meta( $coupon->get_id(), 'discount_amount' ) +  wc_get_order_item_meta( $coupon->get_id(), 'discount_amount_tax' )); ?>
	</tr>
<?php } ?>

Podobné návody

Reklama
Zobrazeno 34 krát.
%d bloggers like this: