• Hello all,

    I am developing a payment processing plugin for my WooCommerce site, and all has been going well so far, except one thing. I have added some fields to the payment section of the checkout of my site, under my plugin, and using/submitting them seems to work as I intended. I was following along with WooCommerce’s official tutorial on their site regarding customizing checkout fields and found that I could not get any of the fields to display the user’s inputs in the WooCommerce Admin Order Menu (I will abbreviate to WAOM).

    Here is the code that I am using to create and display the fields. In particular, note the 74th line, which is the function elavon_order_data_after_billing_address, and the form field starting on the 24th line, which is the field that contains the input I am trying to display in the WAOM. [Also, here is the reference tutorial that I mentioned I was using, which you’ll see is very similar to what I have written.](https://woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/)

    Here is what I’ve found or tried so far regarding research and fixes;
    1.) I looked at Chrome Dev Tools and found that the line that should be displaying the string is giving me this value: <strong>Payment Phone Number:</strong>, as I wrote, followed by, in italics, *==0*, which to me means “null”. To elaborate a bit, the function get_post_meta on line 74, which is appended to the end of that bolded “Payment Phone Number”, requires one parameter, namely, a post ID (int), in this case being the ID of the order I’m trying to get the metadata from. It also has two optional fields, namely the meta key to receive (string), in this case being the phone number, and a boolean used to determine whether or not to return a single value, with the default being “false”, and the parameter not having any effect if there is not a key specified. With this knowledge, it would make sense then that there’s absolutely 0 display, given that there’s this potentially false boolean involved.
    2.) I tried changing, on line 74, the reference $order->id to $order->get-id(), which didn’t seem to do anything. This is the new method of getting the IDs for products, posts, and orders as of WooCommerce 3.0
    3.) I read over the rest of my code multiple times, had another pair of eyes check to make sure I wasn’t crazy, and I’m not sure what else I could be missing. The key is correct, the boolean is set to true, the actions and filters have been added according to the correctly documented method, and there aren’t any typos here anywhere.

    <?php
    
    /**Filters, and actions. Actions are saving the changes we make to the database from our forms.
    * Reference is here: https://woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ 
    */
    
    add_filter ( 'woocommerce_gateway_description', 'elavon_description_fields', 20, 2 );
    add_action ( 'woocommerce_checkout_process', 'elavon_description_fields_validation' );
    add_action ( 'woocommerce_checkout_update_order_meta', 'elavon_checkout_update_order_meta', 10, 1 );
    add_action ( 'woocommerce_admin_order_data_after_billing_address', 'elavon_order_data_after_billing_address', 10, 1 );
    add_action ( 'woocommerce_order_item_meta_end', 'elavon_order_item_meta_end', 10, 3 );
    
    function elavon_description_fields( $description, $payment_id ) {
    
        if ( 'elavon_converge_payments' !== $payment_id ) {
            return $description;
        }
    
        ob_start();
    
        echo '<div style="display: block; width:300px; height:auto;">';
        echo '<img src="' . plugins_url( '../assets/credit-card-icon.png', __FILE__ ) . '">';
        
        woocommerce_form_field(
            'payment_number',
            array(
                'type' => 'text',
                'label' => __( 'Payment Phone Number', 'woo-elavon-converge-payments'),
                'class' => array( 'form-row', 'form-row-wide' ),
                'required' => true,
            )
        );
    
        woocommerce_form_field(
            'paying_network',
            array(
                'type' => 'select',
                'label' => __( 'Payment Network', 'woo-elavon-converge-payments'),
                'class' => array( 'form-row', 'form-row-wide' ),
                'required' => true,
                'options' => array(
                    'none' => __( 'Select a Payment Network', 'woo-elavon-converge-payments'),
                    'Visa' => __( 'Visa', 'woo-elavon-converge-payments'),
                    'MasterCard' => __( 'MasterCard', 'woo-elavon-converge-payments'),
                ),
            )
        );
    
        echo '</div>';
    
        $description .= ob_get_clean();
    
        return $description;
    }
    
    function elavon_description_fields_validation() {
    
        if( 'elavon_converge_payments' === $_POST['payment_method'] && ! isset( $_POST['payment_number'] ) || empty( $_POST['payment_number'] ) ) {
            wc_add_notice( 'Please enter a phone number into the phone number field of the payment gateway', 'error' );
        }
    
    }
    
    function elavon_checkout_update_order_meta( $order_id ) {
    
        if( isset( $_POST['payment_number'] ) || ! empty( $_POST['payment_number'] ) ) {
            update_post_meta( $order_id, $payment_number, $_POST['payment_number'] );
        }   
    
    }
    
    function elavon_order_data_after_billing_address( $order ) {
    
        echo '<p><strong>' . __( 'Payment Phone Number:', 'woo-elavon-converge-payments' ) . '</strong><br>' . get_post_meta( $order->id, 'payment_number', true ) . '</p>';
        
    }
    
    function elavon_order_item_meta_end( $item_id, $item, $order ) {
        echo '<p><strong>' . __( 'Payment Phone Number:', 'woo-elavon-converge-payments' ) . '</strong><br>' . get_post_meta( $order->id, 'payment_number', true ) . '</p>';
    }
    • This topic was modified 2 years, 2 months ago by Evan Kirschenmann. Reason: line breaks were implemented incorrectly for the list
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @evenimous

    I understand that you are developing a payment processing plugin.

    The problems you are encountering are fairly complex development related issues, which happen to fall outside the scope of support we are able to provide in this forum. I’m going to leave this thread open for a bit to see if anyone is able to chime in to help you out here.

    If you’re not receiving input on this thread, we can recommend reaching out to one of the customization experts listed here: https://woocommerce.com/customizations/.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    This specific forum is more focused on the default WooCommerce core features.

    Thread Starter Evan Kirschenmann

    (@evenimous)

    Hi @margaretwporg
    Thank you for pointing me in the right direction. I had previously been looking at various documents on woocommerce.com/document/… , rather than at the developer portal. This will be helpful.

    I will refrain from making posts out of the scope from this point forwards. Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trouble Displaying Payment Gateway Field Data in Woocommerce Admin Order Page’ is closed to new replies.