Integrate Trustpilot’s Automatische Feedback Service With Woocommerce

Try the WooCommerce Trustpilot Plugin now. This plugin sends the Trustpilot’s BCC email after order processing or completing.

Trustpilot is an open, community-based platform for sharing real reviews of shopping experiences online. You can use Trustpilot with your web shop. To ask customs for reviews Trustpilot sends e-mails. When you open a account you get a unique (secret) e-mail-address to send your order information to. Trustpilot’s software scans this e-mails for the e-mail-address of customer and your orderID. Trustpilot use this information to ask your customers for reviews.

With Automatische Feedback Service e-mails are send directly after the order. You can do this by sending a Bcc (blind carbon copy) of your confirmation e-mail to your unique Trustpilot e-mail-address. Woocommerce has no setting to send such Bcc message by default. To send you blind copy you have to change the code of Woocommerce.

Find the file /wp-content/plugins/woocommerce/classes/class-wc-email.php on your webserver first. Trustpilot ask you to send your order conformation e-mail. Woocommerce also sends an order complete message. I use the order complete message to send the blind copy. In the file mentioned before look up the customer_completed_order function. If you prefer to send the blind copy with the confirmation use the customer_processing_order function.

customer_completed_order contain the line:
$headers = apply_filters('woocommerce_email_headers', '', 'customer_processing_order', $order);

Add the following line of code after this line (replace xxxx@trustpilotservice.com with your own unique e-mailaddress):
$headers .= 'Bcc: xxxx@trustpilotservice.com'."\r\n";

That’s all. Remember this solution isn’t a hook for Woocommerce so you have to repeat this steps when you update your Woocommerce plugin every time.

Update for Woocommerce 2 In Woocommerce 2 the structure of the mail class has been changed. To send your Bcc message to Trustpilot you have to add the email address to /wp-content/plugins/woocommerce/classes/emails/class-wc-email-customer-completed-order.php or wc-email-processing-order.php if you like. The function trigger calls $this->send() change the fifth parameter from $this->get_headers() to this->get_headers().'Bcc: xxxx@trustpilotservice.com'."\r\n".

Originele tekst in wordpress plugin aanpassen

Gisteren vroeg @KarinBron op twitter: “I want to change the “succesfully added to cart” string in #WooCommerce #WordPress, of course outside the core files #dtv“. In eerste instantie begreep ik de vraag niet helemaal. Ik dacht dat het ging om het aanpassen van de vertaling. Waar het om ging: In een plugin is een Engelstalige string (tekst) opgenomen. Deze string wordt netjes vertaald via de mee geleverde language files van de plugin. Als gebruiker van de plugin zou je hier misschien liever een andere tekst zien. De snelste oplossing lijkt dus de language files aan te passen. Verondersteld dat de originele taal van de plugin Engels is, dan kan in languages/en_US.po een “vertaling” worden toegevoegd. Je vertaald dan dus de ongewenste Engelse tekst, naar de gewenste Engelse tekst. Dat kun je herhalen voor alle talen. Nadeel in dit geval is dus dat je de originele vertaalbestanden aanpast. Dat moet je elke keer doen als de plugin geupdate is.

Er moet dus een andere oplossing gezocht worden. Ik zal het hier uit leggen voor het specifieke geval waarover de vraag ging. De plugin waar het om gaat is Woocommerce. Deze plugin heeft een bestand woocommerce-functions.php, daarin komt de functie woocommerce_add_to_cart_message()voor. In die functie staat de volgende regel:


$message = sprintf('%s %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );

Het gaat om de tekst “Product successfully added to your cart.”, die tekst willen we aanpassen. Van de betreffende functie kunnen we geen ‘hook’ maken. Een oplossing hiervoor vond ik op remove/add filter to WordPress Function fil….

De output van de functie kan ik dus aanpassen in functions.php van mijn theme. Aan functions.php voeg ik dan dus toe:


function my_filer_function( $message )
{
// Here you should modify $message as you want, and then return it.
$replace = 'Thanks, Product successfully added to your cart.';
$message = preg_replace('/(.*<\/a> )(.*)/',"$1".$replace,$message);
return $message;
}
// Then add the function to that filter hook and prioritize it last
add_filter( 'woocommerce_add_to_cart_message', 'my_filer_function', 999);

De tekst “Product successfully added to your cart.” wordt dus vervangen door de tekst “Thanks, Product successfully added to your cart.”. Op de website heb ik getest of dit ook gebeurd. Dat werkt inderdaad prima. Er is nog een klein probleempje. De tekst wordt namelijk niet meer vertaald als ik de website in een andere taal bekijk.

In de bovenstaande code vervang ik de replace daarom door:

$replace = __('Thanks, Product successfully added to your cart.','your_domain');

De vertaling wordt in dit geval afgehandeld door de language files uit het ‘your_domain’ domein. Dit is onderdeel van mijn theme, omdat ik in functions.php ook heb opgenomen:
//Load the theme translation files
load_theme_textdomain( 'your_domain', TEMPLATEPATH.'/languages' );

Om de nieuwe tekst ook vertaald te krijgen naar bijvoorbeeld het Nederlands, voeg ik deze toe aan “TEMPLATEPATH.’/languages/nl_NL.po'”, daarin zet ik nu:

#: wp_webvrouw5/functions.php:119
msgid "Thanks, Product successfully added to your cart."
msgstr "Bedankt, het product is aan je winkelmandje toegevoegd."

De string is nu vertaald. Alle aanpassingen zijn gemaakt binnen mijn theme en ik kan de plugin dus blijven updaten.
Mocht bij een update van de plugin de structuur (html output) van woocommerce_add_to_cart_message worden aangepast dan zou het kunnen dat de replace niet meer werkt.

Wij wil zien dat het ook echt werkt kan kijken naar: NCFS Knuffelapen. Na het klikken op kopen, zie je de nieuwe tekst in het Nederlands. Nu de aap nog even afrekenen, daarmee steun je het goede doel!