Last active
August 29, 2015 13:57
-
-
Save tareiking/9406547 to your computer and use it in GitHub Desktop.
Create a product category array from a single product in WooCommerce
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
<?php | |
/* Remove Add to Cart button from product loop | |
* Removes all pricing and add to cart buttons from the product loop | |
* Mad props to http://profiles.wordpress.org/daledude/ | |
* For his answer deep here: http://profiles.wordpress.org/daledude/ | |
*/ | |
function abbey_remove_woocommerce(){ | |
global $product, $post; | |
$target_category = 'school-excursions'; | |
// Remove shop items from the Product category page | |
if ( is_product_category( $target_category ) ) { | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); | |
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_meta', 10 ); | |
return; | |
} | |
// Remove shop items from the Single-Product page | |
if ( is_product() ) { | |
$terms = wp_get_post_terms( $post->ID, 'product_cat' ); | |
foreach ( $terms as $term ) $categories[] = $term->slug; | |
if ( in_array( $target_category, $categories ) ){ | |
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10); | |
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40); | |
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); | |
} | |
} | |
} | |
add_action( 'woocommerce_before_shop_loop', 'abbey_remove_woocommerce' ); | |
add_action( 'woocommerce_before_single_product_summary', 'abbey_remove_woocommerce' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment