Linking the order number for Dokan Woocommerce email notifications

556 views Asked by At

I'm using Dokan and about up and running but have a couple issues with the stock email templates from Woocommerce.

  1. On the new order email, the order number is also a link. Ideally, that would link to their order in Dokan. However, the link address is to my (as the admin) wordpress site and directs them to log into wordpress, for which they obviously don't have credentials.

  2. Customers are sent various emails about their orders but the order number text contains no link to the order on my site.

How can we go about adding the correct link into these emails? I'm just learning php so skills are very limited.

Here's the code for admin-new-order & customer-completed-order:

if ( ! defined( 'ABSPATH' ) ) {
    exit;
 }

 /**
  * @hooked WC_Emails::email_header() Output the email header
  */
 do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

 <p><?php printf( __( 'You have received an order from %s. The order is as follows:', 'woocommerce' ), $order->get_formatted_billing_full_name() ); ?></p>

 <?php

 /**


 if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * @hooked WC_Emails::email_header() Output the email header
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

<p><?php printf( __( "Hi there. Your recent order on %s has been completed. Your order details are shown below for your reference:", 'woocommerce' ), get_option( 'blogname' ) ); ?></p>

<?php

/**
 * @hooked WC_Emails::order_details() Shows the order details table.
 * @hooked WC_Structured_Data::generate_order_data() Generates structured data.
 * @hooked WC_Structured_Data::output_structured_data() Outputs structured data.
 * @since 2.5.0
 */
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );

/**
 * @hooked WC_Emails::order_meta() Shows order meta data.
 */
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );

/**
 * @hooked WC_Emails::customer_details() Shows customer details
 * @hooked WC_Emails::email_address() Shows email address
 */
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );

/**
 * @hooked WC_Emails::email_footer() Output the email footer
 */
do_action( 'woocommerce_email_footer', $email );

  * @hooked WC_Emails::order_details() Shows the order details table.
  * @hooked WC_Structured_Data::generate_order_data() Generates structured data.
  * @hooked WC_Structured_Data::output_structured_data() Outputs structured data.
  * @since 2.5.0
  */
 do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );

 /**
  * @hooked WC_Emails::order_meta() Shows order meta data.
  */
 do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );

 /**
  * @hooked WC_Emails::customer_details() Shows customer details
  * @hooked WC_Emails::email_address() Shows email address
  */
 do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );

 /**
  * @hooked WC_Emails::email_footer() Output the email footer
  */
 do_action( 'woocommerce_email_footer', $email );
1

There are 1 answers

1
LoicTheAztec On BEST ANSWER

New order is made for admins or shop managers, that's why the order link is linked to backend order edit pages (only for Admin notifications) .

This order number is located in emails/email-order-details.php

This template can be overridden by copying it to yourtheme/woocommerce/emails/email-order-details.php, see: Template Structure + Overriding Templates via a Theme

If you want to have a link in customer emails that goes on their my account order view page (and same thing for admin email notifications), you need to replace this:

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$text_align = is_rtl() ? 'right' : 'left';

do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>

    <?php if ( ! $sent_to_admin ) : ?>
        <h2><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></h2>
    <?php else : ?>
        <h2><a class="link" href="<?php echo esc_url( admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) ); ?>"><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ); ?>)</h2>
    <?php endif; ?>

By this:

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$text_align = is_rtl() ? 'right' : 'left';

do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>

<?php if ( ! $sent_to_admin ) : ?>
    <h2><a class="link" href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ) . get_option( 'woocommerce_myaccount_view_order_endpoint' ) . '/' . $order->get_order_number(); ?>"><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></a></h2>
<?php else : ?>
        <h2><a class="link" href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ) . get_option( 'woocommerce_myaccount_view_order_endpoint' ) . '/' . $order->get_order_number(); ?>"><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ); ?>)</h2>
    <?php endif; ?>

Now you will have the order number linked to their corresponding my account / order-view page for all notifications, included the admin email notifications as "New Order"…


Update related to the comment (for the correct "vendor" path, the replacement will be:

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$text_align = is_rtl() ? 'right' : 'left';

do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>

<?php if ( ! $sent_to_admin ) : ?>
    <h2><a class="link" href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ) . get_option( 'woocommerce_myaccount_view_order_endpoint' ) . '/' . $order->get_order_number(); ?>"><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></a></h2>
<?php else : ?>
    <h2><a class="link" href="<?php echo home_url( '/' ) . 'dashboard/orders/?order_id=' . $order->get_order_number(); ?>"><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ); ?>)</h2>
<?php endif; ?>