Home Forums WC Vendors Pro Support How to include custom WC checkout field on WCV order page?

NOTICE: We've Moved to a Ticket System for Support

As of August 31, 2017 (12am EST) our support forums will be retired (read-only), and we will be moving to a support ticket system.  This will allow us to better organize and answer support requests, and provide a more personalized experience as we assist our customers.

For the time being, we will leave our forums open for reading and learning while we work on creating a more robust Knowledge Base for everyone to use.

If you are a WC Vendors Pro customer please open a support ticket here. 

If you are a WC Vendors user please open a support ticket on the Wordpress.org forums.

The information on this forum is outdated and in most instances no longer relevant. Please be sure to check our documentation for the most up to date information.

https://docs.wcvendors.com/

Thank you to all of our customers!

 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #58594
    Pablo
    Participant

    Hi,

    So in my marketplace, I’m associating customer’s author link profile with each order that they make. Like this: example.com/author/username

    Right now, the author link is included in order emails and on order pages in Woocommerce. The goal was to showcase author’s(customer) profile to the seller. I achieved this by placing a hidden field in the checkout which gets the author’s profile link upon submission of the checkout form.
    I will post the code below for free use if anyone needs this feature 🙂

    Anyways, what I would like to do now is to showcase these links on Vendor dashboard, specifically among order details. Can you please tell me if this is possible and how would I go on with adding functions that showcases this link on WC Order page?

    Here’s a code:

    add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_hidden_field', 10, 1 );
    function my_custom_checkout_hidden_field( $checkout ) {
    
        // Get an instance of the current user object
        $user = wp_get_current_user();
    
        // The user link
        $user_link = home_url( '/author/' . $user->user_login );
    
        // Output the hidden link
        echo '
                
        ';
    }
    
    add_action( 'woocommerce_checkout_update_order_meta', 'save_custom_checkout_hidden_field', 10, 1 );
    function save_custom_checkout_hidden_field( $order_id ) {
    
        if ( ! empty( $_POST['user_link'] ) )
            update_post_meta( $order_id, '_user_link', sanitize_text_field( $_POST['user_link'] ) );
    
    }
    
    // Showcase link in order emails
    
    add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
    
    function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
        $fields['_user_link'] = array(
            'label' => __( 'User Link' ),
            'value' => get_post_meta( $order->id, '_user_link', true ),
        );
        return $fields;
    }
    
    // Showcase link in order pages
    
    add_action( 'woocommerce_order_details_after_order_table', 'custom_order_details_after_order_table', 10, 1 );
    function custom_order_details_after_order_table( $order ) {
    
        $user_link = get_post_meta( $order->id, '_user_link', true );
    
        echo '<p><a class="author-link" href="'. $user_link .'">'. __( 'Click here to view user profile' ) . '</a><p>';
    
    }
    
    add_action( 'woocommerce_admin_order_data_after_billing_address', 'custom_checkout_field_display_admin_order_meta', 10, 1 );
    
    function custom_checkout_field_display_admin_order_meta($order){
        $user_link = get_post_meta( $order->id, '_user_link', true );
        if ( ! empty( $user_link ) )
            echo '<p>' . __( 'Click here to view user profile' ) . get_post_meta( $order->id, '_user_link', true ) . '</p>';
    
    }
    #58599
    Pablo
    Participant

    The code is deleting itself when I post it here not sure why :/

    #58600
    Pablo
    Participant

    Here is a link to view the code: https://hastebin.com/afaxebolot.php

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘WC Vendors Pro Support’ is closed to new topics and replies.