Попытка получить данные о продукте из последнего заказа, например [key] => pa_size
Использование automatewoo_update_print_file
для вызова файла. php там, где расположены две функции, она вызывается при добавлении новой заметки в заказ:
function automatewoo_update_print_file( $workflow ) {
include '/home/***/public_html/wp-content/themes/***-child/woocommerce/checkout/file.php';
}
Обновление Это хорошо сработало, чтобы получить самый последний идентификатор заказа и получить идентификатор продукта, затем метаданные из идентификатора, а также остальные данные заказа , Но мне все равно нужно тянуть [key] => pa_size
<code>function get_last_order_id(){
global $wpdb;
$statuses = array_keys(wc_get_order_statuses());
$statuses = implode( "','", $statuses );
// Getting last Order ID (max value)
$results = $wpdb->get_col( "
SELECT MAX(ID) FROM {$wpdb->prefix}posts
WHERE post_type LIKE 'shop_order'
AND post_status IN ('$statuses')
" );
return reset($results);
}
$latest_order_id = get_last_order_id(); // Last order ID
$order = wc_get_order( $latest_order_id ); // Get an instance of the WC_Order oject
$order_details = $order->get_data(); // Get the order data in an array
$order_status = $order_details['status'];
foreach ($order->get_items() as $item_key => $item ):
$product_id = $item->get_product_id();
$variation_id = $item->get_variation_id();
$item_name = $item->get_name(); // Name of the product
$quantity = $item->get_quantity();
$product = $item->get_product(); // Get the WC_Product object
$product_price = $product->get_price();
endforeach;
$print_file = get_post_meta( $product_id, 'print_file_url', true );
// Raw output for testing
echo 'Product Price<pre> '; print_r( $product_price ); echo '
'; echo 'Название продукта
'; print_r( $item_name ); echo '
'; echo 'Количество продукта
'; print_r( $quantity ); echo '
'; echo 'ID продукта
'; print_r( $product_id ); echo '
'; echo 'ID варианта
'; print_r( $variation_id ); echo '
'; echo 'URL файла печати
'; print_r( $print_file ); echo '
'; echo 'Статус заказа
'; print_r( $order_status ); echo '
'; echo 'ID последнего заказа
'; print_r( $latest_order_id ); echo '
'; echo 'Детали заказа
'; print_r( $order_details ); echo '
';