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 | |
/** | |
* Add in your themes functions.php | |
* Exclude featured product in the main product loop | |
*/ | |
add_action( 'woocommerce_product_query', function ($query) { | |
if ( ! is_admin() && $query->is_main_query() ) { | |
// Not a query for an admin page. |
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 | |
/* | |
Show featured products first. Above the normal product list | |
*/ | |
add_action('woocommerce_before_main_content', function() { | |
if(is_product_category()) { | |
$current_term = get_queried_object(); | |
echo '<h2> Featured '.esc_html($current_term->name).'</h2>'; |
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 | |
/* | |
Show featured products first. Before the normal product list | |
*/ | |
add_action('woocommerce_before_shop_loop', function() { | |
if(is_product_category()) { | |
$current_term = get_queried_object(); | |
echo do_shortcode('[featured_products_by_category cat="'.$current_term->slug.'" limit=3]'); |
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 | |
// Display featured products by category. on this case its "shirts" which is the slug of the category. | |
$query_args = array( | |
'featured' => true, | |
'category' => array( 'shirts' ), | |
); | |
$products = wc_get_products( $query_args ); | |
global $post; |
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 | |
// Get featured products by category. on this case its "shirts" which is the slug of the category. | |
$query_args = array( | |
'featured' => true, | |
'category' => array( 'shirts' ), | |
); | |
$products = wc_get_products( $query_args ); |
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 | |
// Get products by category. on this case its "shirts" which is the slug of the category. | |
$query_args = array( | |
'category' => array( 'shirts' ), | |
); | |
$products = wc_get_products( $query_args ); |
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
add_action( 'wp_enqueue_scripts', function(){ | |
//remove generator meta tag | |
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) ); | |
//first check that woo exists to prevent fatal errors | |
if ( function_exists( 'is_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 | |
/** | |
* Plugin Name: View Price In Cart | |
* Plugin URI: https://gist.github.com/jameshwartlopez/ad675a295b8e6f3062db4835f0613dc2 | |
* Description: WooCommerce extension for making the product prices as a link to cart | |
* Author: Jameshwart Lopez | |
* Author URI: https://github.com/jameshwartlopez | |
* Version: 1.0 | |
*/ |
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
function hide_price_if_not_logged_in( $price ) { | |
$isLoggedIn = is_user_logged_in(); | |
if(false == $isLoggedIn){ | |
//return empty html price | |
return ''; | |
} | |
return $price; | |
} |
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
//Option One (if you decided to use Option Two then remove this function and its action hook) | |
function remove_add_cart_button(){ | |
$isLoggedIn = is_user_logged_in(); | |
if(false == $isLoggedIn){ | |
//if the user is not login then remove add to cart button by removing the action hook | |
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); | |
} | |
} | |
add_action('wp','remove_add_cart_button'); |