Skip to content

Instantly share code, notes, and snippets.

View tanmay27vats's full-sized avatar

Tanmay Vats tanmay27vats

View GitHub Profile
@tanmay27vats
tanmay27vats / function.php
Created July 18, 2017 06:01
Get product's default variation ID, variation price or variation object without plugin.
function tv_find_matching_product_variation( $product, $attributes )
{
foreach( $attributes as $key => $value )
{
if( strpos( $key, 'attribute_' ) === 0 )
{
continue;
}
unset( $attributes[ $key ] );
@tanmay27vats
tanmay27vats / function.php
Created July 4, 2017 06:00
Enable SVG support in Wordpress. How to upload/enable SVG images on wordpress.
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
function fix_svg_thumb_display() {
echo '<style type="text/css">
td.media-icon img[src$=".svg"], img[src$=".svg"].attachment-post-thumbnail {
width: 100% !important;
@tanmay27vats
tanmay27vats / function.php
Created June 26, 2017 11:46
Show "Stock Out" if all variations are stock out.
function wc_show_variable_product_stock_out()
{
global $product;
if( $product->is_type( 'variable' ) )
{
$args = array(
'post_type' => 'product_variation',
'post_status' => array( 'private', 'publish' ),
'numberposts' => -1,
'orderby' => 'menu_order',
@tanmay27vats
tanmay27vats / script.js
Last active January 5, 2024 22:58
Custom Add to cart WooCommerce, Refresh fragments data, Refresh cart total items, Get product variation
product_add_to_cart : function(){
var ajx_data = {};
var ajx_grab = {};
$(document).on('change','.single-product .variations_form select',function(e){
var $this = $(this);
var pro_id = $(".single-product .variations_form").attr('data-product_id');
var attribute_name = $this.attr('data-attribute_name');
var attribute_value = $this.val();
var post_ajxurl = window.location+"?wc-ajax=get_variation";
@tanmay27vats
tanmay27vats / ios_push_notification.php
Last active May 28, 2018 04:41
Apple Push Notification service (APNs) - iOS Push Notification in PHP
<?php
// Provide the Host Information.
$vHost = 'gateway.sandbox.push.apple.com';
//$vHost = 'gateway.push.apple.com';
$vPort = 2195;
// Provide the Certificate and Key Data.
$vCert = 'Certificates.pem';
@tanmay27vats
tanmay27vats / update.sql
Created April 24, 2017 08:40
Renaming Custom Post Types and Taxonomies Through MySQL Query - Wordpress
SQL query for renaming the posts:
UPDATE `wp_posts` SET `post_type` = '<new post type name>' WHERE `post_type` = '<old post type name>';
SQL query for renaming taxonomy:
UPDATE `wp_term_taxonomy` SET `taxonomy` = '<new taxonomy name>' WHERE `taxonomy` = '<old taxonomy name>';
# That should take care of all of the database areas. Just remember to match the new names in the code where the post types or taxonomies are registered. As far as I know, this is not handled in any plugins yet.
@tanmay27vats
tanmay27vats / bash.sh
Created April 24, 2017 08:36
change editor for git
git config --global core.editor "vim"
#Run above command in Terminal / git-bash to change git editor from default to "vim" editor
@tanmay27vats
tanmay27vats / yahoo_weather.php
Last active July 23, 2018 12:03
Yahoo weather YQL API without authentication / No OAuth required - PHP script
<?php
class Yahoo_Weather
{
protected $base_url = "http://query.yahooapis.com/v1/public/yql";
protected $location = false;
protected $units = false;
protected $current = false;
protected $future = false;
protected $data = false;
@tanmay27vats
tanmay27vats / shopify-variant-filters.txt
Created March 9, 2017 13:07
Showing Shopify product's variants (Size / Length / Color) as filters on collection page.
/*****
Here, I am assuming that you have already assigned all variants as tags of a product. Because Shopify filter does not work with variant options.
And, if you assigns all variants as tags you can not differentiate them from tags.
Here I code that is working for 2 filters Size & Length (with mulitple options. ie mulitple sizes, multiple lengths, etc
*****/
<div class="filters-toolbar">
<div class="filters-toolbar__item size-filter">
{% assign variant_sizes = "" %}
{% assign variant_lengths = "" %}
@tanmay27vats
tanmay27vats / function.php
Last active April 18, 2024 08:30
Remove "Product Type/Product Data" Dropdown Options - WooCommerce
add_filter( 'product_type_selector', 'remove_product_types' );
function remove_product_types( $types ){
unset( $types['grouped'] );
unset( $types['external'] );
unset( $types['variable'] );
return $types;
}