Skip to content

Instantly share code, notes, and snippets.

View vishalkakadiya's full-sized avatar
:octocat:

Vishal Kakadiya vishalkakadiya

:octocat:
View GitHub Profile
@vishalkakadiya
vishalkakadiya / gist:8769f333897810419f514414f9dbe131
Created May 6, 2016 07:10 — forked from corsonr/gist:9152652
WooCommerce : add custom fields to product variations
<?php
//Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 3 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
//Save variation fields
add_action( 'woocommerce_process_product_meta_variable', 'save_variable_fields', 10, 1 );
/**
@vishalkakadiya
vishalkakadiya / manage_columns_wp_admin.php
Last active March 16, 2024 01:08
Manage custom columns with sortable in WordPress Admin side
<?php
/*
* =================================================================================================
* Below both hooks works for custom post types.
* e.g. Suppose we have custom post-type name : Books
* @ref https://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column
* =================================================================================================
*/
@vishalkakadiya
vishalkakadiya / Custom-Admin-Settings.php
Last active April 26, 2019 15:31
How to add custom settings in WordPress Admin ?
<?php
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@vishalkakadiya
vishalkakadiya / woocommerce-settings-tab-demo.php
Created November 27, 2016 18:58 — forked from BFTrick/woocommerce-settings-tab-demo.php
A plugin demonstrating how to add a WooCommerce settings tab.
<?php
/**
* Plugin Name: WooCommerce Settings Tab Demo
* Plugin URI: https://gist.github.com/BFTrick/b5e3afa6f4f83ba2e54a
* Description: A plugin demonstrating how to add a WooCommerce settings tab.
* Author: Patrick Rauland
* Author URI: http://speakinginbytes.com/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
@vishalkakadiya
vishalkakadiya / gist:c2ba3e1ee05af2d69f78d732c2be7cc8
Created December 13, 2016 19:55 — forked from hissy/gist:7352933
[WordPress] Add file to media library programmatically
<?php
$file = '/path/to/file.png';
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $parent_post_id,
@vishalkakadiya
vishalkakadiya / Install Composer using MAMP's PHP.md
Created January 13, 2017 15:38 — forked from irazasyed/Install Composer using MAMP's PHP.md
Instructions on how to change preinstalled Mac OS X PHP to MAMP's PHP Installation and then install Composer Package Management

Change default Mac OS X PHP to MAMP's PHP Installation and Install Composer Package Management


Instructions to Change PHP Installation


First, Lets find out what version of PHP we're running (To find out if it's the default version).

To do that, Within the terminal, Fire this command:

which php

Go to this directory
For Mac Users
/usr/local/pear/share/pear/PHP/CodeSniffer/Standards
For Linux Users
/usr/share/php/PHP/CodeSniffer/Standards/
then
@vishalkakadiya
vishalkakadiya / functions.php
Created June 25, 2017 17:55
WooCommerce snippets to calculate tax/shipping based on country code.
<?php
if ( ! function_exists( 'vk_get_tax_cost_by_country' ) ) {
/**
* Get tax cost by country code.
*
* @param string $country_code Code of country.
* @param int $total Cart total.
*
* @return int Cost of tax.
@vishalkakadiya
vishalkakadiya / commands.txt
Created August 3, 2017 19:54
Commands to Upgrade PHPcs and WordPress_Coding_Standards
// Update PHPcs
sudo pear upgrade-all and sudo pear install PHP_CodeSniffer
// Check version of PHPcs
phpcs --version
// Go to Where coding standards available
/usr/local/pear/share/pear/PHP/CodeSniffer/Standards/WordPress-Coding-Standards
@vishalkakadiya
vishalkakadiya / functions.php
Last active October 13, 2017 12:43
WordPress most useful hooks(It was used for one project, I directly copy paste it. So use it as per your requirements.)
<?php
/**
* File contains all hooks related to Submission post type.
*
* Required in customizer.php.
*
* @package vk-research
*/
/**