init();
}
public function init()
{
global $wpdb;
add_shortcode('wooacd-custom-request', array($this, 'custom_request_shortcode'));
add_action('wp_ajax_wooacd_grab_local_url', array($this, 'grab_local_url')); // Call when user logged in
add_action('wp_ajax_nopriv_wooacd_grab_local_url', array($this, 'grab_local_url')); // Call when user in not
$db_cart = $wpdb->prefix . 'wooacd_custom_cart';
$rowCount = $wpdb->get_var("SELECT COUNT(DATE_FORMAT(`created_at`,'%YYYY-%m-%d')) FROM $db_cart WHERE DATE(`created_at`) = CURDATE()");
if( $rowCount < 5 ){
add_action('wp_ajax_wooacd_submit_request', array($this, 'submit_request')); // Call when user logged in
add_action('wp_ajax_nopriv_wooacd_submit_request', array($this, 'submit_request')); // Call when user in not
}else{
add_action('admin_notices', array($this,'acl_wooacd_admin_notice'));
}
add_action('wp_footer', array($this, 'custom_request_form'));
add_shortcode('wooacd-custom-request-search', array($this, 'custom_request_again_shortcode'));
add_action('wp_ajax_wooacd_custom_request_window', array($this, 'custom_request_window')); // Call when user logged in
add_action('wp_ajax_nopriv_wooacd_custom_request_window', array($this, 'custom_request_window')); // Call when user in not
if (get_option('acl_wooacd_price_breakdown') == 'enable') {
add_action('woocommerce_order_item_meta_end', array($this, 'wooacd_breakdown_button'), 10, 4);
}
$customRequestSettings = get_option('acl_wooacd_custom_request');
if (!empty($customRequestSettings) && in_array("shop", $customRequestSettings)) {
add_action('woocommerce_after_shop_loop_item', array($this, 'add_custom_request_in_shop'), 10, 4);
}
if (!empty($customRequestSettings) && in_array("product", $customRequestSettings)) {
//add_action('woocommerce_after_add_to_cart_button', array($this, 'add_custom_request_in_single_page'), 10, 4);
add_action('woocommerce_single_product_summary', array($this, 'add_custom_request_in_single_page'), 10, 4);
//add_filter('woocommerce_short_description', array($this, 'add_custom_request_in_single_page'), 10, 4);
}
}
public function acl_wooacd_admin_notice()
{
$class = 'notice notice-error';
$message = __("Your Today's Custom Request limit is over!!! if you want unlimited custom request buy our pro version", "acl-wooacd");
printf('
%2$s
', esc_attr($class), esc_html($message));
}
public function custom_request_shortcode()
{
return '';
}
public function custom_request_again_shortcode()
{
$html = "";
$html .= '
';
$html .= '';
$html .= '';
$html .= '
';
$html .= '';
return $html;
}
public function custom_request_window()
{
ob_clean();
$link = wc_clean($_POST['product_link']);
$title = $this->wooacd_get_title($link);
$content = ob_get_clean();
echo wp_send_json(array('title' => $title));
wp_die();
}
public function wooacd_get_title($url)
{
$str = wp_remote_retrieve_body(wp_remote_get($url));
if (strlen($str) > 0) {
$str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside
preg_match("/\(.*)\<\/title\>/i", $str, $title); // ignore case
return $title[1];
}
return $title;
}
//public function
public function custom_request_form()
{
?>
Request Item
prefix . 'wooacd_custom_cart';
$db_notifications = $wpdb->prefix . 'wooacd_notifications';
if (!is_user_logged_in()) {
$first_name = wc_clean($_POST['full_name']);
$email = wc_clean($_POST['email']);
$phone_number = wc_clean($_POST['phone_number']);
$user_id = username_exists($email);
//$user_id = email_exists($email);
if (!$user_id and email_exists($email) == false) {
//$response = 'dgdg';exit;
$random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
//$user_id = wp_create_user($name, $random_password, $email);
$user_id = wp_insert_user(array(
'first_name' => $first_name,
'user_pass' => $random_password,
'user_login' => $email,
'user_email' => $email,
'phone' => $phone_number,
'role' => 'customer',
));
// $to = $_POST['email']; //sendto@example.com
// $subject = 'The subject';
// $body = 'The email body content';
// $headers = array('Content-Type: text/html; charset=UTF-8');
//wp_mail($to, $subject, $body, $headers);
if (!is_wp_error($user_id)) {
wp_mail($email, 'Login Details', 'Hi ' . $first_name . '!, Welcome to our Site. This is your username : ' . $first_name . ' and password : ' . $random_password);
wp_set_current_user($user_id, $email);
wp_set_auth_cookie($user_id);
//do_action('wp_login', $name);
$response['status'] = 200;
$response['message'] = __('Your account has been created.', '');
} else {
$response['status'] = 403;
$response['message'] = __($user_id->get_error_message(), '');
}
} else {
$response['status'] = 300;
$response['redirect_url'] = get_permalink(wc_get_page_id('myaccount')); //my account login url
$response['message'] = __('Your username already exist, please login now', '');
}
} else {
$user_id = get_current_user_id();
$response['status'] = 200;
//$response['message'] = __('You are already logged in.', '');
}
if (is_user_logged_in()) {
$insert_id = $wpdb->insert($db_cart, array(
'product_name' => $this->wooacd_get_title(wc_clean($_POST['product_link'])),
'product_link' => wc_clean($_POST['product_link']),
'notes' => wc_sanitize_textarea($_POST['note']),
'quantity' => wc_clean($_POST['quantity']),
'user_id' => $user_id,
'cart_type' => 2, // saved item=1, pending item = 2
'product_type' => 2, // local product =1, out product = 2
));
if ($insert_id) {
$wpdb->insert($db_notifications, array(
'notification_message' => "You have been requested for new product. Please review it.",
'sender_id' => $user_id,
'sender_type' => 2, // admin = 1, customer = 2
'receiver_id' => null,
'receiver_type' => 1, // admin = 1, customer = 2
'order_id' => null,
'notification_for' => 3, //1=order-message, 2=order-status, 3= customer-request
'custom_cart_id' => $wpdb->insert_id,
'notificated_at' => date('Y-m-d H:i:s', strtotime('now')),
'status' => 0, //0 = unread, 1 = read
));
}
$response['redirect_url'] = wc_get_account_endpoint_url('custom-cart'); //my account login url
$response['message'] .= __('Requested item submitted successfully!.', '');
}
echo wp_send_json($response);
}
public function action_function_name_4492()
{
global $post;
$order = wc_get_order($post->ID);
foreach ($order as $item_id => $item) {
// Here you get your data
$custom_field = wc_get_order_item_meta($item_id, '_tmcartepo_data', true);
// To test data output (uncomment the line below)
// If it is an array of values
if (is_array($custom_field)) {
echo implode(' ', $custom_field); // one value displayed by line
} // just one value (a string)
else {
echo $custom_field;
}
}
}
public function wooacd_breakdown_button($item, $order)
{
$breakdown = get_post_meta($order->get_product_id(), '_wooacd_cost_breakdown');
if (!empty($breakdown)) {
?>