Skip to content

Instantly share code, notes, and snippets.

Kartik Parmar kartikparmar

Block or report user

Report or block kartikparmar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kartikparmar
kartikparmar / functions.php
Created Dec 12, 2019
Hide WooCommerce Category and its sub-categories from Shop page
View functions.php
<?php
/**
* Show products only of selected category.
*/
function get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
$hide_category = array( 126 ); // Ids of the category you don't want to display on the shop page
@kartikparmar
kartikparmar / functions.php
Created Nov 27, 2019
Adding free product to cart when a product is added to cart has category A or B or C
View functions.php
<?php
/**
* Automatically adding the product to the cart.
*/
function aaptc_add_product_to_cart( $item_key, $product_id ) {
$product_category_id = array( 16, 17, 18 ); // Category ids of A, B and C
$product_cats_ids = wc_get_product_term_ids( $product_id, 'product_cat' );
$product_category_id_check = false;
@kartikparmar
kartikparmar / functions.php
Created Sep 11, 2019
Removing products from a particular category on the shop page.
View functions.php
<?php
function hpcs_hide_products_category_shop( $query ) {
$tax_query = (array) $query->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'chairs' ), // Category slug here
@kartikparmar
kartikparmar / functions.php
Last active Aug 30, 2019
Multiplying the rate if the any product in the cart falls under the specified categories.
View functions.php
<?php
add_filter( 'woocommerce_package_rates','overwrite_shipping_cost', 100, 2 );
function overwrite_shipping_cost($rates, $package ) {
global $woocommerce;
if ( get_field( 'multiplier', 'option' ) ) :
$multiplier = get_field( 'multiplier', 'option' );
else :
$multiplier = 1;
@kartikparmar
kartikparmar / functions.php
Created Aug 30, 2019
Automatically adding the gift product to cart when specified criteria match
View functions.php
<?php
/*
* Automatically adding gift product to the cart
* Click on Add to Cart of Product A(under category cricket bat) will automatically add Gift A to cart
* Click on Add to Cart of Product B(under category cricket bat) will automatically add Gift A to cart
* Click on Add to Cart of Gift A will not automatically add Gift A to cart
*/
function aaptc_add_product_to_cart( $item_key, $product_id ) {
@kartikparmar
kartikparmar / functions.php
Last active Aug 30, 2019
Automatically adding multiple products to the cart based on the multiple categories.
View functions.php
<?php
/*
* Automatically adding multiple products to the cart based on the multiple categories.
*/
function aaptc_add_product_to_cart( $item_key, $product_id ) {
$product_category_id = array( 17, 18 ); // Category ids Hoodies & T-Shirts
$product_cats_ids = wc_get_product_term_ids( $product_id, 'product_cat' ); // Getting assigned categories of product which is being added to cart
@kartikparmar
kartikparmar / quantity-input.php
Created Aug 22, 2019
Customizing the validation message when custom tries to add to cart with more than allowed quantity.
View quantity-input.php
<?php
/**
* Product quantity inputs
*
* This template can be overridden by copying it to yourtheme/woocommerce/global/quantity-input.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@kartikparmar
kartikparmar / functions.php
Created Jun 27, 2019
Return all category ids of WooCommerce
View functions.php
<?php
function wcget_category_ids(){
$orderby = 'name';
$order = 'asc';
$hide_empty = false ;
$cat_args = array(
'orderby' => $orderby,
'order' => $order,
@kartikparmar
kartikparmar / functions.php
Last active Feb 25, 2019
Removing free product when cart doesn't contains product of particular category.
View functions.php
<?php
/**
* Removing free product from cart when cart doensn't contains product of perticular category.
*/
function remove_product_from_cart() {
// Run only in the Cart or Checkout Page
if ( is_cart() || is_checkout() ) {
@kartikparmar
kartikparmar / functions.php
Created Jan 30, 2019
Remove WooCommerce Product of specific category from shop page
View functions.php
<?php
function exclude_product_of_specific_category( $q ) {
if ( is_shop() ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
You can’t perform that action at this time.