Viewing 2 replies - 1 through 2 (of 2 total)
  • katmac_aus

    (@katmac_aus)

    Have used your plugin for many years. Would be great to get HPOS available so I can keep using it? Any updates on this. The plugin currently says:

    ⚠ This plugin is incompatible with the enabled WooCommerce feature ‘High-Performance order storage’, it shouldn’t be activated.

    greencode

    (@greencode)

    @windischweb @katmac_aus With the help of ChatGPT and Claude.ai I’ve managed to make this HPOS compatible. If you’re comfortable editing the plugin files then replace all of the content in the woo-friendly-user-agent.php file with this

    <?php
    /**
    * Plugin Name: Friendly User Agent for WooCommerce
    * Plugin URI:
    * Description: Show the order user agent in a user friendly view on the orders page.
    * Version: 1.4.0
    * Tested up to: 6.5
    * Requires PHP: 5.6
    * WC requires at least: 3.0.0
    * WC tested up to: 8.0.0
    * Author: Blaze Concepts
    * Author URI: https://www.blazeconcepts.co.uk/
    *
    * Text Domain: woo-friendly-user-agent
    *
    */
    if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
    }

    /**
    * Declare HPOS compatibility
    */
    add_action( 'before_woocommerce_init', function() {
    if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
    \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
    }
    } );

    /**
    * Enable Languages
    *
    * @return void
    */
    add_action( 'init', 'blz_fua_load_plugin_textdomain' );

    function blz_fua_load_plugin_textdomain() {
    $domain = 'woo-friendly-user-agent';
    $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
    load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
    }

    include_once dirname( __FILE__ ) . '/parse-user-agent.php';

    /**
    * Add Friendly User Agent to single order page
    *
    * @param [object] $order
    * @return void
    */
    add_action( 'woocommerce_admin_order_data_after_billing_address', 'blz_fua_show_user_agent_admin_order' );

    function blz_fua_show_user_agent_admin_order($order) {

    $agent = $order->get_customer_user_agent();

    if ( !isset($agent) || empty($agent) ) {
    // Not set don't output
    } else {
    echo '<div class="single_order_ua"><strong>'.__('Customer User Agent','woo-friendly-user-agent').':</strong><br> '.blz_fua_getFriendlyAgent($agent).'</div>';
    }

    }

    /**
    * Add Friendly User Agent column to orders list page (legacy tables)
    *
    * @param [array] $columns
    * @return $new_columns
    */
    add_filter('manage_edit-shop_order_columns', 'blz_fua_add_order_agent_column_header', 20);

    function blz_fua_add_order_agent_column_header( $columns ) {

    $new_columns = array();

    foreach ( $columns as $column_name => $column_info ) {

    $new_columns[ $column_name ] = $column_info;

    if ( 'order_total' === $column_name ) {
    $new_columns['order_agent'] = __( 'User Agent', 'woo-friendly-user-agent' );
    }
    }

    return $new_columns;
    }

    /**
    * Add Friendly User Agent column to orders list page (HPOS)
    */
    add_filter( 'woocommerce_shop_order_list_table_columns', 'blz_fua_add_order_agent_column_header_hpos', 20 );

    function blz_fua_add_order_agent_column_header_hpos( $columns ) {
    $new_columns = array();

    foreach ( $columns as $column_name => $column_info ) {
    $new_columns[ $column_name ] = $column_info;

    if ( 'total' === $column_name ) {
    $new_columns['order_agent'] = __( 'User Agent', 'woo-friendly-user-agent' );
    }
    }

    return $new_columns;
    }

    /**
    * Display Friendly User Agent in column on orders list page (legacy tables)
    *
    * @param [string] $column
    * @return void
    */
    add_action('manage_shop_order_posts_custom_column', 'blz_fua_add_order_agent_column_content');

    function blz_fua_add_order_agent_column_content( $column ) {
    global $post;

    if ( 'order_agent' === $column ) {

    $order = wc_get_order( $post->ID );
    $agent = $order->get_customer_user_agent();

    if ( !isset($agent) || empty($agent) ) {
    $output = __('Not set','woo-friendly-user-agent');
    } else {
    $output = blz_fua_getFriendlyAgent($agent);
    }

    echo $output;
    }
    }

    /**
    * Display Friendly User Agent in column on orders list page (HPOS)
    */
    add_action( 'manage_woocommerce_page_wc-orders_custom_column', 'blz_fua_add_order_agent_column_content_hpos', 10, 2 );

    function blz_fua_add_order_agent_column_content_hpos( $column, $order ) {
    if ( 'order_agent' === $column ) {
    $agent = $order->get_customer_user_agent();

    if ( !isset($agent) || empty($agent) ) {
    $output = __('Not set','woo-friendly-user-agent');
    } else {
    $output = blz_fua_getFriendlyAgent($agent);
    }

    echo $output;
    }
    }

    /**
    * Get Friendly User Agent and return output
    *
    * @param [string] $agent
    * @return $output
    */
    function blz_fua_getFriendlyAgent($agent) {
    $friendlyagent = blz_fua_parse_user_agent($agent);

    $output = '';

    if(isset($friendlyagent['platform']) && !empty($friendlyagent['platform'])){
    $output .= __('Platform','woo-friendly-user-agent').': '.$friendlyagent['platform'];
    } else {
    $output .= __('Platform: Not known','woo-friendly-user-agent');
    }

    if(isset($friendlyagent['imgplatform']) && !empty($friendlyagent['imgplatform'])){
    $output .= '<img src="'.$friendlyagent['imgplatform'].'" width="15" height="15" />';
    }
    $output .= '<br>';

    if(isset($friendlyagent['browser']) && !empty($friendlyagent['browser'])){
    $output .= __('Browser','woo-friendly-user-agent').': '.$friendlyagent['browser'];
    } else {
    $output .= __('Browser: Not known','woo-friendly-user-agent');
    }

    if(isset($friendlyagent['imgbrowser']) && !empty($friendlyagent['imgbrowser'])){
    $output .= '<img src="'.$friendlyagent['imgbrowser'].'" width="15" height="15" />';
    }
    $output .= '<br>';

    if(isset($friendlyagent['version']) && !empty($friendlyagent['version'])){
    $output .= __('Version','woo-friendly-user-agent').': '.$friendlyagent['version'];
    }

    return $output;
    }

    /**
    * Add admin CSS
    *
    * @return void
    */
    add_action( 'admin_print_styles', 'blz_fua_add_order_agent_column_style' );

    function blz_fua_add_order_agent_column_style() {
    $css = '.post-type-shop_order .wp-list-table td.column-order_agent,
    .woocommerce-page.page-wc-orders .wp-list-table .order_agent.column-order_agent {
    width: 9%;
    line-height: 20px;
    }
    .post-type-shop_order .wp-list-table td.column-order_agent img,
    .woocommerce-page.page-wc-orders .wp-list-table .order_agent.column-order_agent img {
    vertical-align: middle;
    margin-left: 5px;
    }
    .post-type-shop_order .single_order_ua,
    .woocommerce-page.page-wc-orders .single_order_ua {
    line-height: 20px;
    }
    .post-type-shop_order .single_order_ua img,
    .woocommerce-page.page-wc-orders .single_order_ua img {
    vertical-align: middle;
    margin-left: 5px;
    }';
    wp_add_inline_style( 'woocommerce_admin_styles', $css );
    }

    Basically added Added HPOS Compatibility Declaration

    add_action( 'before_woocommerce_init', function() {
    if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
    \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
    }
    } );

    Added Support for HPOS Order List Columns

    add_filter( 'woocommerce_shop_order_list_table_columns', 'blz_fua_add_order_agent_column_header_hpos', 20 );

    Added HPOS Order Column Content Handler

    add_action( 'manage_woocommerce_page_wc-orders_custom_column', 'blz_fua_add_order_agent_column_content_hpos', 10, 2 );

    And Updated CSS for HPOS Compatibility (Added CSS selectors to target both traditional and HPOS order list views). Updated Version Number and WC Tested Up To (Increased version to 1.4.0 and updated WC tested up to 8.0.0)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘HPOS compatibility’ is closed to new replies.