woocommerce offtopic – Pull line item data from plugin

Question

I am trying to display a line item meta (designid) on invoices. To do so I need to pull line item meta from one plugin to another using a custom function.

The custom plugin that displays the data on WooCommerce order details page is as follows:

    public static function init() {
        add_action( 'woocommerce_before_order_itemmeta', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
    }


    public static function add_order_item_meta( $item_id, $item, $order ) {
        $jumbo_data = $item->get_meta( 'jumbo_data' );
        if ( ! $jumbo_data ) {
            return;
        }

        $webservice = new jumbo_Webservice();

        
        try {
            $designid = $webservice->get_designid( $jumbo_data['design'] );
        } catch ( Exception $e ) {
            $designid = 'not found';
        }

        ?>
        
            <p><?php esc_html_e( 'Design ID' ); ?>: <?php esc_html_e( $designid  ); ?></p>

I need to display the design ID ($designid) on invoices.

The invoice plugin developer says I need to use the following function to display custom data on invoices:

    // Add Design ID 
function mypc_add_invoice_fields( $fields, $order ) {

    $jumbo_designid = '-----';
    
    if ( $jumbo_designid  ) {
        $fields['design'] = array(
            'label' => __( 'Design ID', 'mypc' ),
            'value' => $jumbo_designid ,
        );

    }

    return $fields;
}

add_filter( 'wcdn_order_info_fields', 'mypc_add_invoice_fields', 10, 2 );

How can I pull the designid into a custom function?

0
Rob 2 weeks 2022-11-20T13:39:13-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse