Enter your fast order here
Please enter the product code(s) and quantities and click ‘Add To Basket’.
Not logged in
return ob_get_clean();
}
add_action('wp_ajax_get_for_favourites', 'get_for_favourites');
add_action('wp_ajax_nopriv_get_for_favourites', 'get_for_favourites');
function get_for_favourites(){
$data = $_REQUEST['data'];
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'orderby' => 'title',
'post_status' =>'publish',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_sku',
'value' => $data['sku'],
'compare' => 'like'))
);
$query = new WP_Query($args);
$result = '';
if($query->have_posts()){
$posts = $query->posts;
foreach ($posts as $post){
$id = $post->ID;
$result = array('title' => get_the_title($id), 'product_id' => $id);
}
}else{
$result .= array('Not found');
}
echo json_encode($result);
die();
//return $posts;
}
add_action('wp_ajax_add_to_favourites', 'add_to_favourites');
add_action('wp_ajax_nopriv_add_to_favourites', 'add_to_favourites');
function add_to_favourites(){
$data = $_REQUEST['data'];
$user_id = get_current_user_id();
$meta_key = $data['type'].'_favourites';
$_id = $data['id'];
$favourites = array();
$_favourites =get_user_meta($user_id, $meta_key, true);
$favourites = unserialize($_favourites);
$res = 'false';
if($favourites && !in_array($_id, $favourites)){
array_push( $favourites,$_id);
$_favourites =serialize($favourites);
update_user_meta($user_id,$meta_key,$_favourites);
$res = 'true';
}elseif(!$favourites){
$_favourites =serialize(array($_id));
update_user_meta($user_id,$meta_key,$_favourites);
$res = 'true';
}
echo $res;
die();
}
add_action('wp_ajax_get_favourites', 'get_favourites');
add_action('wp_ajax_nopriv_get_favourites', 'get_favourites');
function get_favourites($type=false){
$data = $_REQUEST['data'];
$user_id = get_current_user_id();
if(isset($data)){
$type = $data['type'];
}
$meta_key = $type.'_favourites';
$_favourites =get_user_meta($user_id, $meta_key, true);
$favourites=false;
if($_favourites){
$favourites = unserialize($_favourites);
}
$result = '';
if(!empty($favourites)){
$args = array(
'posts_per_page' => -1,
'post_type' => $type,
'orderby' => 'title',
'post__in' => $favourites,
'post_status' =>'publish',
'order' => 'ASC',
);
$query = new WP_Query($args);
if($query->have_posts()){
$posts = $query->posts;
foreach ($posts as $post){
$id = $post->ID;
$result .= ''.get_the_title($id).
'
';
}
}else{
$result = 'No favourites
';
}
}else{
$result = 'No favourites
';
}
echo $result;
if(isset($data)){
die();
}
}
function get_favourites_ids($type=false){
$user_id = get_current_user_id();
//error_log($user_id);
$meta_key = $type.'_favourites';
//error_log($meta_key);
$_favourites =get_user_meta($user_id, $meta_key, true);
$favourites=false;
if($_favourites){
$favourites = unserialize($_favourites);
}
return $favourites ;
}
add_action('wp_ajax_remove_from_favourites', 'remove_from_favourites');
add_action('wp_ajax_nopriv_remove_from_favourites', 'remove_from_favourites');
function remove_from_favourites(){
$data = $_REQUEST['data'];
$user_id = get_current_user_id();
$type = $data['type'];
$_id = $data['id'];
$meta_key = $data['type'].'_favourites';
$favourites = array();
$_favourites =get_user_meta($user_id, $meta_key, true);
$favourites = unserialize($_favourites);
$pos = array_search($_id, $favourites);
$res = 'false';
if($pos !== false){
unset($favourites[$pos]);
$_favourites =serialize($favourites);
update_user_meta($user_id,$meta_key,$_favourites);
$res = 'true';
}
echo $res;
die();
}
function render_favourite_section($title, $post_type){
if(isset($_POST['submit-add-to-cart'])) {
add_product_to_cart();
}
?>
Product Code
QTY
Product Name