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>';
}