Skip to content

Instantly share code, notes, and snippets.

View spraveenitpro's full-sized avatar

Praveen spraveenitpro

View GitHub Profile
@spraveenitpro
spraveenitpro / gist:420c0bb48fadd23543a9
Created June 11, 2015 05:45
Skip Cart Page in WooCommerce
add_filter ('add_to_cart_redirect', 'redirect_to_checkout');
function redirect_to_checkout() {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();
return $checkout_url;
}
@spraveenitpro
spraveenitpro / gist:34a21efa5b33b00d1aba
Last active August 29, 2015 14:22
Fetch Attribute name and value from a WooCommerce product
<?php
global $woocommerce; //Declare GLobal
$ourproduct = new WC_Product(629); //Initialize/fetch Product with id 629
$attribute = $ourproduct->get_attributes( ); //Get the attributes for the above fetched product
echo $attribute['product-code']['name']; //Print The Attribute Name
echo $attribute['product-code']['value']; //Print the Attribute value
?>
@spraveenitpro
spraveenitpro / gist:0767f6321cf068314686
Created June 8, 2015 12:53
Custom step for Measure Price calculator
function sv_wc_measurement_price_calculator_amount_needed() {
wc_enqueue_js( '
$( "input.amount_needed" ).attr( { "step" : "0.1", "type" : "number" } );
' );
}
add_action( 'wp_enqueue_scripts', 'sv_wc_measurement_price_calculator_amount_needed' );
@spraveenitpro
spraveenitpro / gist:3101e74464bbd81116d9
Last active August 29, 2015 14:22
Display Empty Categories on shop page
/*
* Display Empty Categories
*
*/
add_filter( 'woocommerce_product_subcategories_hide_empty', 'show_empty_categories', 10, 1 );
function show_empty_categories ( $show_empty ) {
$show_empty = true;
return $show_empty;
@spraveenitpro
spraveenitpro / gist:764ec9adabc659b28247
Created May 27, 2015 03:32
Extract the Regular and Sale price from a Product
<?php
global $woocommerce;
$ourproduct = new WC_Product(562);
print_r($ourproduct);
echo "<br>".$ourproduct->regular_price;
echo "<br>".$ourproduct->sale_price;
?>
@spraveenitpro
spraveenitpro / gist:76199e13961bfd351253
Created May 27, 2015 03:20
Extract the first Coupon value used in an order
<?php
global $woocommerce;
$order = new WC_Order(1255);
$order_coupons = $order->get_used_coupons();
$coupon= $order_coupons[0];
$coupon_value= new WC_Coupon($coupon);
echo $coupon_value->coupon_amount;
?>
@spraveenitpro
spraveenitpro / gist:f5973034f8a1ca2bf40c
Created April 24, 2015 06:11
Hide Empty Product categories on the Product category Widget in sidebar
function woo_hide_product_categories_widget( $list_args ){
$list_args[ 'hide_empty' ] = 1;
return $list_args;
}
add_filter( 'woocommerce_product_categories_widget_args', 'woo_hide_product_categories_widget' );
@spraveenitpro
spraveenitpro / gist:cd7da93f078fb4eb2572
Created February 12, 2015 11:35
// Alter Terms and Conditions Error Message
// Alter Terms and Conditions Error Message
function my_woocommerce_add_error( $error ) {
if( 'You must accept our Terms &amp; Conditions.' == $error ) {
$error = 'Please check the box at the bottom of this page';
}
return $error;
}
add_filter( 'woocommerce_add_error', 'my_woocommerce_add_error' );
@spraveenitpro
spraveenitpro / gist:18feadd7cdfaba221af3
Created February 6, 2015 15:12
Remove "Sort By" select from Shop page
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
@spraveenitpro
spraveenitpro / gist:48aaf17940d244b3544f
Created February 4, 2015 10:39
Removing result count
remove_action( ‘woocommerce_before_shop_loop’, ‘woocommerce_result_count’, 20 );