Skip to content

Instantly share code, notes, and snippets.

View jameshwartlopez's full-sized avatar

Jameshwart Lopez jameshwartlopez

  • Pulpogan Consolacion Cebu
View GitHub Profile
@jameshwartlopez
jameshwartlopez / ExcludeFeaturedProductInTheMainProductLoop.php
Last active July 25, 2020 09:23
Exclude featured product in the main product loop or remove any featured product from regular archive loop. See https://jameshwartlopez.com/plugin/remove-any-product-that-is-featured-from-regular-display-loop/
<?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.
<?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>';
<?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]');
<?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 );
@jameshwartlopez
jameshwartlopez / script.js
Last active June 22, 2020 02:59
Unload unneccessary woocommerce js and css
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' ) ) {
@jameshwartlopez
jameshwartlopez / view-price-in-cart.php
Last active July 25, 2017 11:16
View Price In Cart
<?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
*/
@jameshwartlopez
jameshwartlopez / functions.php
Created July 23, 2017 16:02
Hide Woocommerce price for not logged in users
function hide_price_if_not_logged_in( $price ) {
$isLoggedIn = is_user_logged_in();
if(false == $isLoggedIn){
//return empty html price
return '';
}
return $price;
}
@jameshwartlopez
jameshwartlopez / functions.php
Last active December 16, 2022 04:04
Remove/Hide add to cart button in Woocommerce if the user is not logged in
//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');