get_api()->log_to_meta( $context ); if ( ! $response->success ) { Logger::log( 'Bad response from log_to_meta request', [], array( 'should_send_log_to_meta' => false, 'should_save_log_in_woocommerce' => true, 'woocommerce_log_level' => \WC_Log_Levels::ERROR, ) ); } } catch ( \Exception $e ) { Logger::log( 'Error persisting error logs: ' . $e->getMessage(), [], array( 'should_send_log_to_meta' => false, 'should_save_log_in_woocommerce' => true, 'woocommerce_log_level' => \WC_Log_Levels::ERROR, ) ); } } /** * Utility function for sending exception logs to Meta. * * @since 3.5.0 * * @param Throwable $error error object * @param array $context optional error message attributes */ public static function log_exception_to_meta( Throwable $error, array $context = [] ) { $extra_data = WC_Facebookcommerce_Utils::get_context_data( $context, 'extra_data', [] ); $extra_data['php_version'] = phpversion(); $request_data = [ 'event' => WC_Facebookcommerce_Utils::get_context_data( $context, 'event', 'error_log' ), 'event_type' => WC_Facebookcommerce_Utils::get_context_data( $context, 'event_type' ), 'exception_message' => $error->getMessage(), 'exception_trace' => $error->getTraceAsString(), 'exception_code' => $error->getCode(), 'exception_class' => get_class( $error ), 'order_id' => WC_Facebookcommerce_Utils::get_context_data( $context, 'order_id' ), 'promotion_id' => WC_Facebookcommerce_Utils::get_context_data( $context, 'promotion_id' ), 'incoming_params' => WC_Facebookcommerce_Utils::get_context_data( $context, 'incoming_params' ), 'extra_data' => $extra_data, ]; // Check if Action Scheduler is available if ( function_exists( 'as_enqueue_async_action' ) ) { as_enqueue_async_action( 'facebook_for_woocommerce_log_api', array( $request_data ) ); } else { // Handle the absence of the Action Scheduler Logger::log( 'Action Scheduler is not available.', [], array( 'should_send_log_to_meta' => false, 'should_save_log_in_woocommerce' => true, 'woocommerce_log_level' => \WC_Log_Levels::DEBUG, ) ); } } }