Skip to content

Instantly share code, notes, and snippets.

View imran-khan1's full-sized avatar

Imran Khan imran-khan1

  • WordPress Developer
  • Pakistan
View GitHub Profile
<?php
function ik_wc_discount_total() {
global $woocommerce;
$discount_total = 0;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
if ( $_product->is_on_sale() ) {
$regular_price = $_product->get_regular_price();
<?php
/**
* product title with sku
*/
function woo_product_title_with_sku() {
global $product;
echo '<span class="loop-title-sku">Sku: ' . $product->get_sku() . '</span><br>';
}
<?php
/*
custom action hook
*/
do_action( 'my_custom_action' );
//Place the code for the action when fired
function my_action_something_cool() {
<?php
/*
custom filter hook
*/
function custom_filter_something_cool() {
$output = 'Hello World';
return apply_filters('my_custom_filter', $output);
<?php
/*
update cart on quantity field value change
*/
function wc_qty_change_update_cart(){?>
<script>
jQuery(".qty").blur(function(){
jQuery("[name='update_cart']").trigger("click");
<?php
/*
update checkout on billing postcode field blur
*/
function wc_field_blur_update_checkout(){?>
<script>
jQuery("#billing_postcode").blur(function(){
jQuery( 'body' ).trigger( 'update_checkout' );
<?php
/*
update cart on quantity field value change
*/
add_action( 'wp_footer', 'wc_qty_change_update_cart' );
function wc_qty_change_update_cart() {
if (is_cart()) :
?>
<?php
/*
* Notification on order processing to cancelled status change
*/
function ci_cancelled_notification( $order_id ) {
$order = wc_get_order( $order_id );
// load the mailer class
<?php
/**
* Insert the new endpoint into the My Account menu.
*
* @param array $items
* @return array
*/
function ci_custom_account_menu_items( $items ) {
// Remove the logout menu item.
$logout = $items['customer-logout'];
<?php
/*
*Add WooCommerce checkout Custom shipping field
*/
add_filter( 'woocommerce_checkout_fields' , 'ci_custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function ci_custom_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_fax'] = array(