This code below will send a BCC:
add_filter( 'woocommerce_email_headers', 'firefog_headers_filter_function', 10, 2);
function firefog_headers_filter_function( $headers, $object ) {
if ($object == 'new_order') {
$headers .= 'BCC: NAME <name#domain.com>' . "\r\n";
}
return $headers;
}
But how can i apply the below code to the BCC email?
<script type="application/json+trustpilot">
{
"recipientName": "Dynamic code...",
"recipientEmail": "Dynamic code...",
"referenceId": "Dynamic code...",
"locale": "Dynamic code..."
}
</script>
From the trustpilot documentation,
The structured data snippet needs to be included in the source code of
the transactional email that you’re using to trigger AFS.
It’s very important to note that the snippet must be implemented with
the dynamic placeholders used by your specific platform.
It is suggested to add the snippet to the source code of the email. So you can use WooCommerce email hooks to add the snippet.
add_action( 'woocommerce_email_after_order_table', 'add_trustpilot_snippet', 20, 2 );
function add_trustpilot_snippet( $order, $sent_to_admin ) {
?>
<script type="application/json+trustpilot">
{
"recipientEmail": "<?php echo $order->billing_email; ?>",
"recipientName": "<?php echo $order->billing_first_name.' '. $order->billing_last_name; ?>",
"referenceId": "<?php echo $order->get_order_number(); ?>",
}
</script>
}
This will give you an idea about how to implement the feature. Make use of $sent_to_admin variable if you need to target admin emails.
For more WooCommerce email hooks, refer the below link
https://www.businessbloomer.com/woocommerce-visual-hook-guide-emails/
Related
I have a holiday letting wordpress site which has the advanced custom field "Supplier Email" in the add listing page. When a rental is booked the Supplier Email needs to be added to the woocommerce New Order email under BCC, i have tried numerous options but they have not worked, the Supplier Email is in the post meta so it needs to be pulled in to the new order email. This is the code i have in my functions.php file:
add_filter( 'woocommerce_email_headers', 'bcc_to_email_headers', 10, 3 );
function bcc_to_email_headers( $headers, $email_id, $order ) {
if ( $email_id === 'new_order' ) {
$supplier_email = get_field( 'supplier_email_main',$post_id);
if ( $supplier_email ) {
$headers .= "CC: Supplier <" . $supplier_email . ">\r\n";
$headers .= "BCC: New Order <myemail#gmail.com>" . "\r\n";
}
}
return $headers;
}
The gmail address(this would go to my personal email, have hidden it here for obvious reasons) i added to BCC didnt even get sent. Not sure how to proceed with this, any help would be greatly appreciated, please note i am not a wordpress developer. Thanks in advance.
try this
add_filter( 'woocommerce_email_headers', 'add_bcc_header', 10, 3 );
function add_bcc_header( $headers, $id, $order ) {
if ( $id == 'new_order' ) {
$headers .= 'Bcc: gmailaddress#gmail.com' . "\r\n";
}
return $headers;
}
I'm new in plugin development. I would like to use this simple function in Wordpress to send mail to users. I saw this code in the documentation everything is simple and straight forward but this code returns false. Why ?
require_once explode( 'wp-content', __FILE__ )[0] . 'wp-load.php';
function send_mail() {
$to = 't.testmail#gmail.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
$send_message = wp_mail( $to, $subject, $body, $headers );
if ( $send_message ) {
echo 'Email was sent';
} else {
echo 'Email sending was aborted';
}
}
send_mail();
According to the documentation (https://developer.wordpress.org/reference/functions/wp_mail/) the mail could not be sent.
Reasons could be many. Have you checked the debug log of WordPress (https://wordpress.org/support/article/debugging-in-wordpress/)?
Function and filter to display a player post titles:
function wpb_after_post_content($content){
if (is_single()) {
$id=get_the_ID();
$post_meta=get_post_meta(get_the_ID(), 'enclosure', TRUE);
$mp3=explode('.mp3',$post_meta);
$title=get_the_title();
if(count($mp3)>1)
{
$player = '<div class="post_player">' . do_shortcode('[fap_track url="'.trim($mp3[0]).'.mp3" title=url="'.$title.'" share="" cover="" meta="" layout="list" enqueue=no auto_enqueue=yes]')."</div>";
$content=$player.$content;
}
}
if (is_single()) {
$id=get_the_ID();
$post_meta=get_post_meta(get_the_ID(), 'enclosure', TRUE);
$mp3=explode('.mp3',$post_meta);
$title=get_the_title();
if(count($mp3)>1)
{
$player = '<div class="zoomsounds_player">'. do_shortcode('[zoomsounds_player source="'.trim($mp3[0]).'.mp3" play_in_footer_player="on" config="default" artistname="'.get_post_meta($id, 'arxiu_de_so', true).'" config="" ]');
/**if (wp_is_mobile())*/ {
if(get_post_meta($id, 'arxiu_de_so', true)!=""){
/** $player .= " <p id='arxiu_so'> Arxiu de so: ".get_post_meta($id, 'arxiu_de_so', true)."</p>";*/
/**$player .= '<span id="arxiuVal" style="opacity:1"> '.get_post_meta($id, 'arxiu_de_so', true).'</span>';*/
}
}
$player .="</div>";
$content=$player.$content;
}
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
The above code works fine with the_content filter and displays the player below the featured image. However, when I use this function with the the_title filter, the page doesn't load at all. The reason I want to use the_title is because I want the player to display above the featured image but below the post title.
Screenshot:-
This screenshot is to show that with the_content the player displays however it displays below post image.
Please have a look as below:
If you want to use the_title(), then you no need to pass the post_id in the the_title(), we have some params for the_title() if you want to add them like as below:
$before
(string) (Optional) Markup to prepend to the title.
Default value: ''
$after
(string) (Optional) Markup to append to the title.
Default value: ''
$echo
(bool) (Optional) Whether to echo or return the title. Default true for the echo.
Default value: true
If you want to use get_the_title(), then you must need to pass post_id inside the get_the_title($postId);
According to your code snippet, you must update your code with as below for get_the_title():
<?php
function wpb_after_post_content($content){
if (is_single()) {
$id=get_the_ID();
$post_meta=get_post_meta(get_the_ID(), 'enclosure', TRUE);
$mp3=explode('.mp3',$post_meta);
$title=get_the_title($id);
if(count($mp3)>1) {
$player = '<div class="post_player">' . do_shortcode('[fap_track url="'.trim($mp3[0]).'.mp3" title=url="'.$title.'" share="" cover="" meta="" layout="list" enqueue=no auto_enqueue=yes]')."</div>";
$content=$player.$content;
}
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
?>
And for the the_title(), you should update your code with as below:
<?php
function wpb_after_post_content($content){
if (is_single()) {
$id=get_the_ID();
$post_meta=get_post_meta(get_the_ID(), 'enclosure', TRUE);
$mp3=explode('.mp3',$post_meta);
$title=get_the_title();
if(count($mp3)>1)
{
$player = '<div class="post_player">' . do_shortcode('[fap_track url="'.trim($mp3[0]).'.mp3" title=url="'.the_title().'" share="" cover="" meta="" layout="list" enqueue=no auto_enqueue=yes]')."</div>";
$content=$player.$content;
}
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
?>
NOTE: You have not declared the title parameter in the zoomsounds_player shortcode so please pass and update accordingly.
I hope it would help you out.
I am looking to add the shipping address from the order to the New Order email. Can anyone please provide detailed information on how to do so? I am pretty new to editing functions.php, hooks, etc.
Thanks
Use this
you can comment out the conditional part if you want to have it on customer email as well.
add_action( 'woocommerce_email_after_order_table', 'woocommerce_add_shipping_address_to_admin_emails', 15, 2 );
function woocommerce_add_shipping_address_to_admin_emails( $order, $is_admin_email ) {
if ( $is_admin_email ) {
echo '<p><strong>Shipping Address:</strong> ' . $order->get_formatted_shipping_address() . '</p>';
}
}
Thank you for this snippet. It works perfectly! Here is a version which separates header (shipping address) from content:
add_action( 'woocommerce_email_after_order_table', 'woocommerce_add_shipping_address_to_admin_emails', 15, 2 );
function woocommerce_add_shipping_address_to_admin_emails( $order, $is_admin_email ) {
if ( $is_admin_email ) {
$header = '<p><strong>Shipping Address:</strong> ' . '</p>';
$shippingInfo = '<p>' . $order->get_formatted_shipping_address() . '</p>';
echo $header;
echo $shippingInfo;
}
}
I know this is a common error but I haven't come across any solutions that have worked. I'm creating a plugin that uses custom post types and I have a settings page under that CPT's menu. The settings page displays fine but when I go to save the settings I get the error ERROR: options page not found. Here is my settings class:
class Settings {
private $view;
public function __construct( $view ) {
$this->view = $view;
add_action( 'admin_menu', array( $this, 'submenu' ) );
add_action( 'admin_init', function () {
add_settings_section(
'saw_hours',
'Hours Settings', // Title
array( $this, 'settings' ),
'saw_hours_settings'
);
} );
}
public function submenu()
{
add_submenu_page(
"edit.php?post_type=saw_hours", // Parent slug
"Settings", // Page title
"Settings", // Menu title
"activate_plugins", // Role required
'saw_hours_settings', // Menu slug
array($this->view, 'admin'));
}
public function settings()
{
// API key setting
register_setting(
'saw_hours',
'saw_hours_api_key'
);
add_settings_field(
'saw_hours_api_key',
'Set API Key:',
function(){
$clientId = get_option('saw_hours_api_key');
echo '<input type="text" name="saw_hours_api_key" value="' . $clientId . '" >';
},
'saw_hours_settings',
'saw_hours'
);
// Client ID setting
register_setting(
'saw_hours',
'saw_hours_client_id'
);
add_settings_field(
'saw_hours_client_id',
'Set Client ID:',
function(){
$clientId = get_option('saw_hours_client_id');
echo '<input type="text" name="saw_hours_client_id" value="' . $clientId . '" >';
},
'saw_hours_settings',
'saw_hours'
);
}
}
And here is the form page:
<form method="POST" action="options.php">
<?php settings_fields( 'saw_hours' ); ?>
<?php do_settings_sections( 'saw_hours_settings'); ?>
<?php submit_button(); ?>
</form>
I'm at a loss, any help would be appreciated.
Found an answer here:
https://wordpress.stackexchange.com/questions/139660/error-options-page-not-found-on-settings-page-submission-for-an-oop-plugin
This doesn't really answer why register_setting() isn't adding the property to the list of whitelisted properties. If anyone has a better understanding of what's going here I'd love to hear.