функция wc_get_order
-
Друзья, подскажите то делаю не так. Использую Woocommerce и не могу понять в одном случае функция wc_get_order успешно отрабатывает в другом выдаёт ошибку. Хотя код один и тот же. Не могу понять уже всю голову сломал. В первом случае в отображении заявок успешно работает во втором случае в админке вываливает ошибку: Fatal error: Call to a member function get_order() on a non-object in Z:\home\wptest.ru\www\wp-content\plugins\woocommerce\includes\wc-order-functions.php on line 54
function tetso_function() { global $woocommerce; $customer_orders = get_posts( array( 'numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(), 'post_type' => array ( 0 => 'shop_order', 1 => 'shop_order_refund', ), 'post_status' => array ( 0 => 'wc-pending', 1 => 'wc-processing', 2 => 'wc-on-hold', ) ) ); //var_export($customer_orders); if ( $customer_orders ) { foreach ( $customer_orders as $customer_order ) { $order = wc_get_order(); $order->populate( $customer_order ); echo $order->get_order_number().' '; echo $order->get_status().' '; echo strtotime( $order->order_date ).'<br>'; } } } // отображать в my_account add_action('woocommerce_before_my_account', 'tetso_function'); // отображать в админке в списке заявок if (isset($_GET['post_type'])) { $tmp_post_type=$_GET['post_type']; if ('shop_order'==$tmp_post_type) { tetso_function(); } }
Тема «функция wc_get_order» закрыта для новых ответов.