prefix . $this->db_table;
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
assigned_time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
category_id bigint NOT NULL,
email_template varchar(200) NOT NULL,
email_address varchar(200) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY `category_id` (`category_id`)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql);
add_option($this->preifx . 'version', $this->db_version);
}
public function add_plugin_menu() {
add_menu_page('Additional Email', 'Additional Email', 'manage_options', 'aefo_list', array($this, 'aefo_list'));
add_submenu_page('aefo_list', 'Additional Email Add', 'Add Template', 'manage_options', 'aefo_add', array($this, 'aefo_add'));
add_submenu_page('Additional Email Edit', 'Additional Email Edit', 'Add Template', 'manage_options', 'aefo_edit', array($this, 'aefo_edit'));
}
public function aefo_add() {
global $wpdb;
if ($_POST['submit']) {
$data = $_POST;
unset($data['submit']);
$data['assigned_time'] = date('Y-m-d H:i:s');
$wpdb->insert($wpdb->prefix . $this->db_table, $data);
$message = '
';
if ($wpdb->dbh->errno == '1062') {
$message = 'Email already assigned to this category
';
}
}
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0;
$pad_counts = 0;
$hierarchical = 1;
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$all_categories = get_categories($args);
$select = '';
$mailer = WC()->mailer();
$email_templates = $mailer->get_emails();
?>
update($wpdb->prefix . $this->db_table, $data, array('id' => intval($_GET['aefo_item'])));
$message = '';
if ($wpdb->dbh->errno == '1062') {
$message = 'Email already assigned to this category
';
}
}
$data = $wpdb->get_row('select * from ' . $wpdb->prefix . $this->db_table . ' where id=' . intval($_GET['aefo_item']));
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0;
$pad_counts = 0;
$hierarchical = 1;
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$all_categories = get_categories($args);
$select = '';
$mailer = WC()->mailer();
$email_templates = $mailer->get_emails();
?>
mailer();
$order = new WC_Order($order_id);
$items = $order->get_items();
foreach ($items as $item) {
$terms = get_the_terms($item['product_id'], 'product_cat');
foreach ($terms as $term) {
$product_cat_id = $term->term_id;
$item = $wpdb->get_row('select * from ' . $wpdb->prefix . $this->db_table . ' where category_id=' . $product_cat_id);
if ($item) {
$emailtemplate = $email->emails[$item->email_template];
$emailtemplate->object = $order;
$emailtemplate->find['order-number'] = '{order_number}';
$emailtemplate->find['order-date'] = '{order_date}';
$emailtemplate->replace['order-number'] = $order_id;
$emailtemplate->replace['order-date'] = date_i18n(wc_date_format(), strtotime($order->order_date));
$subject = str_replace($emailtemplate->find, $emailtemplate->replace, $emailtemplate->get_subject());
$message = $emailtemplate->get_content();
$email->send($item->email_address, $subject, $message);
unset($item);
unset($emailtemplate);
}
}
}
}
function aefo_list() {
include_once 'class.php';
$list = new AEFO_List($this->db_table);
$list->prepare_items();
?>