Skip to content

Instantly share code, notes, and snippets.

@mklasen
Last active April 29, 2019 12:09
Show Gist options
  • Save mklasen/93b5026e85be1b062941329865a8dcbc to your computer and use it in GitHub Desktop.
Save mklasen/93b5026e85be1b062941329865a8dcbc to your computer and use it in GitHub Desktop.
Add content to Woocommerce e-mails with ACF Fields
<?php
$acf_field = array(
'key' => 'woocommerce_emails',
'label' => 'Woocommerce e-mails',
'name' => 'woocommerce_emails',
'type' => 'repeater',
'layout' => 'row',
'sub_fields' => array(
array(
'key' => 'id',
'label' => 'Woocommerce Template ID',
'name' => 'id',
'type' => 'select',
'choices' => array(
'new_order' => 'New order',
'failed_order' => 'Failed order',
'customer_reset_password' => 'Reset Password (customer)',
'customer_refunded_order' => 'Refund Order (customer)',
'customer_processing_order' => 'Processing order (customer)',
'customer_on_hold_order' => 'On Hold Order (customer)',
'customer_note' => 'Note (customer)',
'customer_new_account' => 'New Account (customer)',
'customer_invoice' => 'Invoice (customer)',
'customer_completed_order' => 'Completed Order (customer)',
'cancelled_order' => 'Cancelled Order',
'customer_estimate_order' => 'Estimate Order',
)
),
array(
'key' => 'email_content',
'label' => 'Content',
'name' => 'email_content',
'type' => 'wysiwyg',
),
),
),
<?php
class Sample {
public function __construct() {
add_action('woocommerce_email_order_details', [ $this, 'add_woocommerce_email_content' ], 1, 4);
}
public function add_woocommerce_email_content( $order, $send_to_admin, $plain_text, $email ) {
$email_settings = get_field('woocommerce_emails', 'option');
foreach ($email_settings as $email_setting) {
if ($email_setting['id'] === $email->id) {
echo $email_setting['email_content'];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment