-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [WC] Refactor the WooCommerce template - [WC] Changed mobile Add-to-cart button to always show instead of being hidden by toggling.
- Loading branch information
Showing
26 changed files
with
313 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('wp-polyfill'), 'version' => '6d476549372716f5015e7a506797b6e8'); | ||
<?php return array('dependencies' => array('wp-polyfill'), 'version' => 'b3a8743c9b023dff76b9420841c5eee1'); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('wp-polyfill'), 'version' => '41aca7e59a974c5118a9e0e1152d235d'); | ||
<?php return array('dependencies' => array('wp-polyfill'), 'version' => '429f50163cc30dac7196ed46d3e00679'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
#adminmenu .toplevel_page_getwooplugins{display:none} | ||
#adminmenu .toplevel_page_getwooplugins{display:none}.woo_variation_swatches_tab{display:none !important} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('wp-polyfill'), 'version' => '6c7fe173069f34ed1a8156c07e51f20a'); | ||
<?php return array('dependencies' => array('wp-polyfill'), 'version' => 'bd46e5b1cda8a6ce66ab214fa8094dab'); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,13 @@ | ||
<?php | ||
global $woocommerce; | ||
$wc_dir = __DIR__ . '/woocommerce'; | ||
|
||
$template = ''; | ||
$args = [ | ||
'woo' => $woocommerce, | ||
'catalog_columns' => get_option('woocommerce_catalog_columns'), | ||
]; | ||
|
||
// SINGLE PRODUCT | ||
if (is_singular('product')) { | ||
global $post; | ||
$template = 'single-product'; | ||
$related_ids = wc_get_related_products($post->ID, $args['catalog_columns']); | ||
|
||
$args = array_merge($args, [ | ||
'post' => $post, | ||
'thumbnail_url' => get_the_post_thumbnail_url($post, 'thumbnail'), | ||
'product' => wc_get_product($post->ID), | ||
'products' => get_posts([ | ||
'post_type' => 'product', | ||
'post__in' => $related_ids, | ||
'orderby' => 'post__in', | ||
]), | ||
'extra_classes' => 'is-style-my-slider', | ||
]); | ||
require_once "{$wc_dir}/single-product.php"; | ||
} | ||
// If SHOP page | ||
elseif (is_shop()) { | ||
$template = 'shop'; | ||
$post = get_post(get_option('woocommerce_shop_page_id')); | ||
|
||
$args = array_merge($args, [ | ||
'post' => $post, | ||
'products' => $wp_query->get_posts(), | ||
]); | ||
} | ||
// if CATEGORY page | ||
elseif(is_product_category() || is_product_tag()) { | ||
global $wp_query; | ||
$template = 'archive-product'; | ||
|
||
$display_mode = woocommerce_get_loop_display_mode(); | ||
$term = get_queried_object(); | ||
|
||
$args['title'] = $term->name; | ||
$args['content'] = wpautop($term->description); | ||
|
||
// if display products | ||
if ($display_mode === 'both' || $display_mode === 'products') { | ||
$args['products'] = $wp_query->get_posts(); | ||
} | ||
|
||
// if display categories | ||
if ($display_mode === 'both' || $display_mode === 'subcategories') { | ||
$args['categories'] = _get_categories($term->term_id); | ||
} | ||
|
||
// disable pagination | ||
if ($display_mode === 'subcategories') { | ||
wc_set_loop_prop('total', 0); | ||
} | ||
} | ||
|
||
get_header(); | ||
get_template_part("woocommerce/views/$template", '', $args); | ||
get_footer(); | ||
|
||
|
||
// | ||
|
||
|
||
/** | ||
* Get WC_Product data from posts and embed it | ||
* | ||
* @param $posts | ||
* @return - Posts with embedded Product data | ||
*/ | ||
function _get_products(array $posts) : array { | ||
$post_ids = array_reduce($posts, function($result, $p) { | ||
$result[] = $p->id; | ||
return $result; | ||
}, []); | ||
|
||
$products = wc_get_products([ | ||
'include' => $post_ids, | ||
'orderby' => 'post__in', | ||
'posts_per_page' => wc_get_loop_prop('total') | ||
]); | ||
|
||
$posts = array_map(function($p, $index) use ($products) { | ||
$p->product = $products[$index]; | ||
return $p; | ||
}, $posts, array_keys($posts)); | ||
|
||
return $posts; | ||
require_once "{$wc_dir}/shop.php"; | ||
} | ||
|
||
|
||
/** | ||
* Get categories / subcategories with attached Thumbnail image and Permalink | ||
* | ||
* @param $parent_id | ||
* @return - The formatted categories | ||
*/ | ||
function _get_categories(int $term_id = 0) : array { | ||
$raw_cats = woocommerce_get_product_subcategories($term_id); | ||
|
||
// get extra data for category | ||
$parsed_cats = array_map(function($c) { | ||
// get thumbnail image | ||
$thumb_id = get_term_meta($c->term_id, 'thumbnail_id', true); | ||
$image = wp_get_attachment_image_src($thumb_id, 'medium'); | ||
$c->image = $image ? $image[0] : wc_placeholder_img_src(); | ||
|
||
// get permalink | ||
$c->link = get_term_link($c->term_id, 'product_cat'); | ||
|
||
return $c; | ||
}, $raw_cats); | ||
|
||
return $parsed_cats; | ||
elseif (is_product_category() || is_product_tag()) { | ||
require_once "{$wc_dir}/archive-product.php"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
global $wp_query; | ||
|
||
$term = get_queried_object(); | ||
$display_mode = woocommerce_get_loop_display_mode(); | ||
|
||
$args = [ | ||
'catalog_columns' => get_option('woocommerce_catalog_columns'), | ||
'title' => $term->name, | ||
'content' => wpautop($term->description), | ||
'pagination' => H::get_pagination(), | ||
]; | ||
|
||
// if display products | ||
if ($display_mode === 'both' || $display_mode === 'products') { | ||
$args['products'] = $wp_query->get_posts(); | ||
} | ||
|
||
// if display categories | ||
if ($display_mode === 'both' || $display_mode === 'subcategories') { | ||
$args['categories'] = _get_categories($term->term_id); | ||
} | ||
|
||
// disable pagination | ||
if ($display_mode === 'subcategories') { | ||
wc_set_loop_prop('total', 0); | ||
} | ||
|
||
get_header(); | ||
get_template_part('woocommerce/views/archive-product', '', $args); | ||
get_footer(); | ||
|
||
|
||
/** | ||
* Get categories / subcategories with attached Thumbnail image and Permalink | ||
* | ||
* @param $parent_id | ||
* @return - The formatted categories | ||
*/ | ||
function _get_categories(int $term_id = 0) : array { | ||
$raw_cats = woocommerce_get_product_subcategories($term_id); | ||
|
||
// get extra data for category | ||
$parsed_cats = array_map(function($c) { | ||
// get thumbnail image | ||
$thumb_id = get_term_meta($c->term_id, 'thumbnail_id', true); | ||
$image = wp_get_attachment_image_src($thumb_id, 'medium'); | ||
$c->image = $image ? $image[0] : wc_placeholder_img_src(); | ||
|
||
// get permalink | ||
$c->link = get_term_link($c->term_id, 'product_cat'); | ||
|
||
return $c; | ||
}, $raw_cats); | ||
|
||
return $parsed_cats; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.