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
/*
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
/*
custom filter hook
*/
function custom_filter_something_cool() {
$output = 'Hello World';
return apply_filters('my_custom_filter', $output);
<?php
/*
custom action hook
*/
do_action( 'my_custom_action' );
//Place the code for the action when fired
function my_action_something_cool() {
<?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
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
function ci_admin_posts_filter( $query )
{
global $pagenow;
if ( is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_SEARCH_FIELD_NAME']) && $_GET['ADMIN_SEARCH_FIELD_NAME'] != '') {
$query->query_vars['meta_value'] = $_GET['ADMIN_SEARCH_FIELD_NAME'];
}
}
<?php
// Customize woocommerce product data tabs
function customize_woo_description_tab( $tabs ) {
$tabs['description']['callback'] = 'woo_description_tab_content'; // Custom description callback
return $tabs;
}
<?php
/**
* Remove woocommerce product data tabs
*/
function remove_woo_product_data_tabs( $tabs ) {
//unset will remove the product tabs
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
<?php
/**
* Reorder woocommerce product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_reorder_product_data_tabs', 98 );
function woo_reorder_product_data_tabs( $tabs ) {
$tabs['reviews']['priority'] = 5; // Reviews first
$tabs['description']['priority'] = 10; // Description second
$tabs['additional_information']['priority'] = 15; // Additional information third
<?php
function woo_custom_physical_product_tab( $tabs ) {
global $product;
// Ensure it doesn't show for virtual products
if ( ! $product->is_virtual() ) {
$tabs['shipping'] = array(
'title' => __( 'Shipping', 'textdomain' ),
'callback' => 'woo_custom_shipping_tab',
'priority' => 50,