I'm trying to add custom content after the order table on the Woocommerce "Processing Order" and "Order Completed" customer emails, using the following code.
It should only be added if the customer chose "Local Pickup" as the shipping method.
// create the module and name it exApp
// also include ngRoute for all our routing needs
var exApp= angular.module('exApp', ['ngRoute']);
// configure our routes
exApp.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
// route for the about page
.when('/about', {
templateUrl : 'pages/about.html',
controller : 'aboutController'
})
// route for the contact page
.when('/contact', {
templateUrl : 'pages/contact.html',
controller : 'contactController'
});
});
// create the controller and inject Angular's $scope
exApp.controller('mainController', function($scope) {
// create a message to display in our view
$scope.message = 'Everyone come and see how good I look!';
});
exApp.controller('aboutController', function($scope) {
$scope.message = 'Look! I am an about page.';
});
exApp.controller('contactController', function($scope) {
$scope.message = 'Contact us! JK. This is just a demo.';
});
The content isn't being added to the emails specified. It's only being added to the "Order Details/Invoice" email that's sent manually through the Woocommerce order admin page.
How can I add the above content to the emails mentioned? What am I doing wrong?
(The email templates aren't overridden in the theme folder)
答案 0 :(得分:2)
这可以通过缺少的挂钩参数$email
轻松定位这些电子邮件通知,这样:
add_action( 'woocommerce_email_after_order_table', 'local_pickup_extra_content_email', 10, 4 );
function local_pickup_extra_content_email( $order, $sent_to_admin, $plain_text, $email ) {
// Only for "Processing Order" and "Order Completed" customer emails
if( ! ( 'customer_processing_order' == $email->id || 'customer_completed_order' == $email->id ) ) return;
$lang = get_post_meta( $order->id, 'wpml_language', true );
if ( $lang == 'he' && && strpos( $order->get_shipping_method(), 'Local Pickup' ) !== false) {
echo '<p><strong>Note:</strong> Please wait for telephone confirmation of local pickup.</p>';
}
}
此代码位于活动子主题(或主题)的function.php文件中或任何插件文件中。
经过测试和工作
类似的答案:Add a custom text to specific email notification for local pickup Woocommerce orders
答案 1 :(得分:1)
由于if语句中的WPML条件,这不起作用:
ICL_LANGUAGE_CODE == "he"
当Woocommerce发送电子邮件时,我不认为ICL_LANGUAGE_CODE存在。为了解决这个问题,我用上面的问题替换了上面问题中的if语句,它就像一个魅力:
$lang = get_post_meta( $order->id, 'wpml_language', true );
if ( $lang == 'he' && && strpos( $order->get_shipping_method(), 'Local Pickup' ) !== false) {
echo '<p><strong>Note:</strong> Please wait for telephone confirmation of local pickup.</p>';
}