Skip to content

Instantly share code, notes, and snippets.

Avatar

Vishal Kothari vishalck

View GitHub Profile
@vishalck
vishalck / woocommerce-hide-prices-shop-category.php
Created Jan 26, 2019
How to Hide Prices on WooCommerce Shop and Category Pages
View woocommerce-hide-prices-shop-category.php
<?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 Aug 2, 2017
Initiate WooCommerce Empty Cart Action
View initiate-empty-cart-action.php
<?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 Aug 2, 2017
Add Empty Cart button on WooCommerce Cart page
View create-empty-cart-button.php
<?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();
View empty-woocommerce-cart.php
<?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 Jun 24, 2017
wc_orders_count() from includes/wc-order-functions.php file.
View wc_orders_count.php
<?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 Jun 23, 2017
Hide count of Processing orders from WooCommerce Orders menu
View hide_processing_order_count.php
<?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 Jun 12, 2017
Show Order Delivery Date on WooCOmmerce Orders Page
View show-delivery-date-on-woocommerce-orders-page.php
<?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 Jun 12, 2017
Populate custom order columns with data
View woocommerce-populate-custom-order-columns.php
<?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
View woocommerce-sort-custom-columns-orders-page.php
<?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 Aug 15, 2019
Add new column to WooCommerce Orders page
View woocommerce-add-new-column-on-orders-page.php
<?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';
You can’t perform that action at this time.