Sharing Passwords
That title probably caught your attention because… when do we ever share passwords?
Actually, we do, a lot. Website administrators often have to share passwords with users and customers who have just been issued a password. Generally that is done automatically, without the administrator ever having any idea what password was shared. You know, for security. And this is something to think about for administrators who are passwording PDF files just before delivery. How will you let the end user know what the PDF password is?
In case you’re stumped, here are some ideas for how to get that information across if you’re running a WooCommerce shop.
The simple way
WooCommerce has a setting for each product under the “Advanced” tab called “Purchase Note.” You can put details for the customer here and it will show on the order confirmation page and in order confirmation emails.
Reasons using this setting might not be best is if you:
- have many products needing different notes
- want your message to appear elsewhere
- need to include dynamic data in the note
- need the note to be translatable
Other options
You probably want to include your message on the order confirmation page and in an order confirmation email. WooCommerce has templates and hooks which allow for you to re-configure these items as desired. This territory is 100% Woo and outside support for our plugins, but we’ll try to point you in the right direction.
Woo Order Confirmation Page
Take a look inside the plugins/woocommerce/templates/checkout folder and you’ll find a file called thankyou.php.
So polite!
This file outputs the content a customer sees upon a successful purchase: an order confirmation. You can override the WooCommerce templates following these instructions, or if you don’t really care to change the page layout/organization, you can just use “hooks” to insert something of your own, like a mention of a password.
Here’s the top of the default order confirmation page (Storefront theme):
Let’s alter that “Thank you. Your order has been received” text:
function order_received_text_with_password( $text, $order ) {
$text = esc_html__( 'Thank you. Your order has been received.', 'woocommerce' );
$text .= '
' . esc_html__( 'Please note!', 'your-text-domain' ) . ' ' . esc_html__( 'Your file download password has been set to your email address.', 'your-text-domain' );
return $text;
}
add_filter( 'woocommerce_thankyou_order_received_text', 'order_received_text_with_password', 11, 2 );
After adding the above PHP code to your (child) theme functions.php file, the order confirmation page will look like this:
This is just a very simple example. If you don’t know how to create a child theme or edit your functions.php file, use the handy Code Snippets plugin to add the PHP code.)
Since the ‘woocommerce_thankyou_order_received_text‘ hook — and indeed most hooks included in the checkout and email templates — includes the WooCommerce $order object as a parameter, you can always use the object to fetch information from the order and print it dynamically in your text. For example, this parameter would come in handy if you were using a customer’s phone number or order number as their PDF password. Then you could actually print a password right on the screen with your message. How do you do this? Here’s a leg up at Stack Overflow about how to get order details from an $order object or order ID. If you are still unsure, please ask your developer. It might also benefit you to read through the PHP code below.
Woo Order Confirmation Page
There are a lot of ways to accomplish changes to the confirmation emails. This is just one:
Take a look inside the plugins/woocommerce/templates/emails folder and you’ll find a file called email-order-details.php. You’ll find two action hooks in this template which can be used to add custom text either above or below the order details table in the email. At the top is the action hook ‘woocommerce_email_before_order_table’; we’ll use that hook in the following example:
function password_before_order_table( $order, $sent_to_admin, $plain_text, $email ) {
$order_data = $order->get_data();
$phone = $order_data['billing']['phone'];
// $order_id = $order->get_id();
// $email is already given as a parameter in case you need to do something with the customer's email
echo 'Please note! Your file download password has been set to your phone number: ' . $phone . '
';
}
add_action( 'woocommerce_email_before_order_table', 'password_before_order_table', 10, 4 );
This code adds the text “Please note! Your file download password has been set to your phone number: 5558675309” in a paragraph above the order details table. To move it below, just use the ‘woocommerce_email_after_order_table’ hook instead. Countless other variations can be done with the WooCommerce templates, so if you’re particular or finicky about what you need from the order confirmation page and order emails, you can chat with a Wordpress developer about re-arranging the WooCommerce templates and/or using hooks to insert your custom (dynamic) content.
Other thoughts
More often than people request a built-in feature to notify customers of their passwords, we receive requests to change the appearance or text of the password prompt in PDF readers. While we are honored that people think we might have control over such a thing, that is way beyond our control. It’s controlled in the realm of countless other developers and designers of PDF reader software. Figure out how to change one software prompt, and you’ll probably still have to figure out how to change the dozens of others. Please let us know when you figure it out!
(advertisement)