Skip to content

Instantly share code, notes, and snippets.

View vishalck's full-sized avatar

Vishal Kothari vishalck

View GitHub Profile
@vishalck
vishalck / woocommerce-hide-prices-shop-category.php
Created January 26, 2019 10:16
How to Hide Prices on WooCommerce Shop and Category Pages
<?php
/**
* Snippet 1: Hide prices on all categories
* Created by: Tyche Softwares
*/
function tyches_hide_prices_on_all_categories( $price, $product ) {
if ( is_tax() ) {
return ''; // Empty string = no price!
}
@vishalck
vishalck / initiate-empty-cart-action.php
Created August 2, 2017 20:42
Initiate WooCommerce Empty Cart Action
<?php
public function woo_empty_cart_action() {
global $woocommerce;
if ( isset( $_REQUEST[ 'emptycart' ] ) && $_REQUEST[ 'emptycart' ] == 'yes' ) {
$woocommerce->cart->empty_cart();
}
}
@vishalck
vishalck / create-empty-cart-button.php
Created August 2, 2017 20:36
Add Empty Cart button on WooCommerce Cart page
<?php
add_action( 'woocommerce_after_cart_contents', array( $this, 'woo_empty_cart' ) );
/**
* Create Empty Cart button on WooCommerce cart page
*/
public function woo_empty_cart() {
global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url();
@vishalck
vishalck / empty-woocommerce-cart.php
Created August 2, 2017 20:29
Empty WooCommerce cart
<?php
/**
* Empties the cart and optionally the persistent cart too.
*
* @param bool $clear_persistent_cart (default: true)
*/
public function empty_cart( $clear_persistent_cart = true ) {
$this->cart_contents = array();
$this->reset( true );
@vishalck
vishalck / wc_orders_count.php
Last active June 24, 2017 11:48
wc_orders_count() from includes/wc-order-functions.php file.
<?php
/**
* Return the orders count of a specific order status.
*
* @param string $status
* @return int
*/
function wc_orders_count( $status ) {
$count = 0;
@vishalck
vishalck / hide_processing_order_count.php
Created June 23, 2017 13:06
Hide count of Processing orders from WooCommerce Orders menu
<?php
add_filter( 'woocommerce_include_processing_order_count_in_menu', 'exclude_processing_order_count' );
function exclude_processing_order_count( $show ) {
$show = false;
return $show;
}
@vishalck
vishalck / show-delivery-date-on-woocommerce-orders-page.php
Created June 12, 2017 13:16
Show Order Delivery Date on WooCOmmerce Orders Page
<?php
// Delivery date & Time in list of orders on WooCommerce Edit Order page in Admin
if ( get_option( 'orddd_show_column_on_orders_page_check' ) == 'on' ) {
add_filter( 'manage_edit-shop_order_columns', array( 'orddd_filter', 'orddd_woocommerce_order_delivery_date_column' ), 20, 1 );
add_action( 'manage_shop_order_posts_custom_column', array( 'orddd_filter', 'orddd_woocommerce_custom_column_value' ), 20, 1 );
add_filter( 'manage_edit-shop_order_sortable_columns', array( 'orddd_filter', 'orddd_woocommerce_custom_column_value_sort' ) );
add_filter( 'request', array( 'orddd_filter', 'orddd_woocommerce_delivery_date_orderby' ) );
}
@vishalck
vishalck / woocommerce-populate-custom-order-columns.php
Last active June 12, 2017 12:58
Populate custom order columns with data
<?php
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
function MY_COLUMNS_VALUES_FUNCTION( $column ) {
global $post;
$data = get_post_meta( $post->ID );
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code
@vishalck
vishalck / woocommerce-sort-custom-columns-orders-page.php
Last active June 12, 2017 12:49
Make custom columns sortable
<?php
add_filter( "manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION' );
function MY_COLUMNS_SORT_FUNCTION( $columns )
{
$custom = array(
'MY_COLUMN_ID_1' => 'MY_COLUMN_1_POST_META_ID',
'MY_COLUMN_ID_2' => 'MY_COLUMN_2_POST_META_ID'
);
return wp_parse_args( $custom, $columns );
@vishalck
vishalck / woocommerce-add-new-column-on-orders-page.php
Last active August 15, 2019 09:05
Add new column to WooCommerce Orders page
<?php
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION( $columns ) {
$new_columns = ( is_array( $columns ) ) ? $columns : array();
unset( $new_columns[ 'order_actions' ] );
//edit this for your column(s)
//all of your columns will be added before the actions column
$new_columns['MY_COLUMN_ID_1'] = 'MY_COLUMN_1_TITLE';