Commit 8b1c16df authored by Nahla Shiri's avatar Nahla Shiri

page variable

parent bdeda2b7
<?php
@ini_set( 'upload_max_size' , '64M' );
@ini_set( 'post_max_size', '64M');
@ini_set( 'max_execution_time', '300' );
@ini_set('upload_max_size', '64M');
@ini_set('post_max_size', '64M');
@ini_set('max_execution_time', '300');
//Get Zones
function get_zones($post_ID = 157){
function get_zones($post_ID = 157) {
if (get_field('zones_commerciaux', $post_ID)):
$i = 0;
while (has_sub_field('zones_commerciaux', $post_ID)) :
if (get_sub_field('list_zones', $post_ID)):
$list_zone = array();
while (has_sub_field('list_zones', $post_ID)) :
$list_zone[]= get_sub_field('num_zone');
$list_zone[] = get_sub_field('num_zone');
endwhile;
endif;
$allZones['zone'.$i] = $list_zone;
$allZones['zone' . $i] = $list_zone;
$i++;
endwhile;
endif;
return json_encode($allZones);
}
//Dequeue CSS
function nap_dequeue_unnecessary_css() {
wp_dequeue_style('additional-parent-style');
......@@ -42,12 +44,12 @@ function nap_dequeue_unnecessary_scripts() {
wp_deregister_script('twentyseventeen-navigation');
//MS : 2017-07-17
wp_register_script( 'getZones', home_url('wp-content/themes/nap/assets'). '/js/map.js' );
wp_register_script('getZones', home_url('wp-content/themes/nap/assets') . '/js/map.js');
$listZones = array('listZones' => get_zones(157));
wp_localize_script( 'getZones', 'zonesL', $listZones );
wp_localize_script('getZones', 'zonesL', $listZones);
// wp_localize_script( 'listZones', 'object_name', $listZones );
wp_enqueue_script( 'getZones' );
wp_enqueue_script('getZones');
//END MS : 2017-07-17
}
......@@ -245,7 +247,7 @@ function nap_load_variation_settings_fields($variations_id) {
function nap_category_image($catID) {
$thumbnail_id = get_woocommerce_term_meta($catID, 'thumbnail_id', true);
$image = wp_get_attachment_image_src($thumbnail_id,'large');
$image = wp_get_attachment_image_src($thumbnail_id, 'large');
return $image[0];
}
......@@ -255,37 +257,7 @@ function nap_attachment_image($pageID) {
return $url;
}
/* add_action( 'woocommerce_after_shop_loop_item', 'nap_variations_loop' );
function nap_variations_loop(){
global $product;
$attributes = $product->get_attributes();
if ( ! $attributes ) {
echo "No attributes";
}
foreach ( $attributes as $attribute ) {
print_r($attribute);
echo $attribute['name'] . ": ";
$product_attributes = array();
$product_attributes = explode('|',$attribute['value']);
$attributes_dropdown = '<select>';
foreach ( $product_attributes as $pa ) {
$attributes_dropdown .= '<option value="' . $pa . '">' . $pa . '</option>';
}
$attributes_dropdown .= '</select>';
echo $attributes_dropdown;
}
}
*/
function nap_menu() {
function nap_menu() {
$menu = "";
$taxonomy = 'product_cat';
......@@ -309,7 +281,7 @@ function nap_attachment_image($pageID) {
foreach ($all_categories as $cat) {
if ($cat->category_parent == 0) {
$category_id = $cat->term_id;
$menu.= '<li data-page = "'.$category_id.'" data-img = "' . nap_category_image($category_id) . '"><a href="' . get_term_link($cat->slug, 'product_cat') . '">' . $cat->name . '</a>';
$menu.= '<li data-page = "' . $category_id . '" data-img = "' . nap_category_image($category_id) . '"><a href="' . get_term_link($cat->slug, 'product_cat') . '">' . $cat->name . '</a>';
$args2 = array(
'taxonomy' => $taxonomy,
......@@ -323,16 +295,16 @@ function nap_attachment_image($pageID) {
'hide_empty' => 1
);
$sub_cats = get_categories($args2);
$menu.= ' <ul class = "subcat" data-page = "'.$category_id.'">';
$menu.= ' <ul class = "subcat" data-page = "' . $category_id . '">';
if ($sub_cats) {
$class = '';
foreach ($sub_cats as $key => $sub_category) {
$subcat_name = explode(' ',$sub_category->name);
$subcat_name = explode(' ', $sub_category->name);
if ($key == 0)
$calss = 'active';
else
$calss = '';
$menu.= '<li data-cover = "' . nap_category_image($sub_category->term_id) . '"><a class="' . $calss . '" href="#cat' . $sub_category->term_id . '">' . $subcat_name[1]. '</a></li>';
$menu.= '<li data-cover = "' . nap_category_image($sub_category->term_id) . '"><a class="' . $calss . '" href="#cat' . $sub_category->term_id . '">' . $subcat_name[1] . '</a></li>';
}
}
......@@ -349,8 +321,30 @@ function nap_variation_url($variationID) {
$couleur = $variable_product->get_attribute('couleur');
$format = $variable_product->get_attribute('format');
$url = '?attribute_couleur=' . trim($couleur) . '&attribute_format=' . trim($format);
return preg_replace('/\s+/','',$url);
$url = '?attribute_couleur=' . $couleur . '&attribute_format=' . $format . '&variation_id=' . $variationID;
return preg_replace('/\s+/', '', $url);
}
function nap_variation_color($variationID) {
$variable_product = wc_get_product($variationID);
$term = get_term_by('name', $variable_product->get_attribute('couleur'), 'pa_couleur');
$termID = $term->term_id;
$color = get_field('couleurs', 'pa_couleur_' . $termID);
return $color;
}
function nap_distinct_color_variations($variations) {
$var_colors = array();
foreach ($variations as $variation) :
$variation_ID = $variation['variation_id'];
$color = nap_variation_color($variation_ID);
if (!in_array($color, $var_colors)):
$var_colors[$variation_ID] = $color;
endif;
endforeach;
return $var_colors;
}
function nap_get_item($post_ID, $args = null, $current_page = '', $options = null) {
......@@ -381,13 +375,10 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul
$variations = get_posts($args);
$temp_colors = array();
foreach ($variations as $key => $value) {
$variable_product = wc_get_product($value->ID);
$term = get_term_by('name', $variable_product->get_attribute('couleur'), 'pa_couleur');
$termID = $term->term_id;
$color = get_field('couleurs', 'pa_couleur_' . $termID);
if (!in_array($color,$temp_colors)){
$color = nap_variation_color($value->ID);
if (!in_array($color, $temp_colors)) {
$temp_colors[] = $color;
$nap_article.='<li data-link = "' . get_permalink($post_ID) . nap_variation_url($value->ID) . '" data-image = "' . get_the_post_thumbnail_url($value->ID, 'small') . '" data-color = "' . $color . '"></li> ';
$nap_article.='<li data-link = "' . get_permalink($post_ID) . nap_variation_url($value->ID) . '" data-image = "' . get_the_post_thumbnail_url($value->ID, 'thumbnail') . '" data-color = "' . $color . '"></li> ';
}
}
$nap_article.='</ul>';
......@@ -398,3 +389,5 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul
return $nap_article;
}
remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
......@@ -132,9 +132,11 @@ $child_category = get_terms('product_cat', array('parent'=>$cateID, 'child_of' =
$args = array('post_type' => 'product', 'stock' => 1, 'posts_per_page' => -1, 'product_cat' => $value->name);
$naps_posts = new WP_Query($args);
$options = array();
$options['size'] = 'small';
while ($naps_posts->have_posts()) : $naps_posts->the_post();
$id = get_the_ID();
$options['size'] = (get_field('produit_affichage',$id ))? get_field('produit_affichage',$id ):'small';
$args = array(
'post_type' => 'product_variation',
'post_status' => array('private', 'publish'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment