Skip to content

Instantly share code, notes, and snippets.

View zainaali's full-sized avatar

Zain Ali zainaali

  • Lahore Punjab, Pakistan
View GitHub Profile
@zainaali
zainaali / gist:5136e11f00a0f7dccfe2e1c047b5dba8
Created April 5, 2021 12:51
set alt tag and title of product images to product's name, category, subcategories' name, vendor's name
add_filter( 'martfury_image_alt_text', 'ct_martfury_image_alt_text' );
add_filter('wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2);
function change_attachement_image_attributes( $attr, $attachment ){
$product_id = get_the_ID();
$vendor_id = get_post_field( 'post_author', $product_id );
// Get the WP_User object (the vendor) from author ID
$vendor = new WP_User($vendor_id);
$vendor_name = $vendor->display_name;
// var_dump($product_cat);exit;
@zainaali
zainaali / gist:8168093a302d9e9858807832f81ba20b
Created August 16, 2021 06:43
Scroll within a div with jQuery animate() function
function scrollingdiv(parentid, id){
$("#"+parentid).animate({scrollTop: $("#"+id).position().top}, 800, 'swing');
}
@zainaali
zainaali / gist:9fd03ffe0f6738c8a74fb4ba7d3b9db4
Created September 10, 2021 09:32
change product quantity based on variation selection
add_action('wp_footer', 'method');
function method()
{
global $post;
//get_product id
$product = get_product( $post->ID );
//if Product is variable add a message
if(is_product() && $product->is_type( 'variable' ) ){
@zainaali
zainaali / gist:d7b0354ddbc240129f8c6b8cc3b9549c
Created November 5, 2021 11:17
Dynamically populate a Contact Form 7 dropdown list form db and add custom validation
add this shortcode in contact from
[select upcoming-gigs data:gigs]
add this code in functions.php
<?php
add_filter('wpcf7_form_tag_data_option', function($n, $options, $args) {
global $wpdb;
$result = $wpdb->get_results("SELECT DATE_FORMAT(termin, '%d.%m.%Y') as termin FROM einweihungen where termin >= CURDATE() ORDER BY einweihungen.termin ASC;");
$optionsarr = array();
@zainaali
zainaali / cursor.html
Created September 15, 2023 10:48
Add color dot cursor instead of default cursor
<!-- Put this html code after <body> tag -->
<div class="mouse-cursor cursor-outer"></div>
<div class="mouse-cursor cursor-inner"></div>
<!--Put this js code in footer -->
<script>
jQuery(document).ready(function($) {
function mousecursor() {
@zainaali
zainaali / solar.html
Created December 11, 2023 08:12
Google Solar API JS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Google Maps Autocomplete</title>
<style>
body{
background: #1a202c;
color:white;