Skip to content

Instantly share code, notes, and snippets.

View santanup789's full-sized avatar

Santanu Patra santanup789

  • Webskitters
  • India
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<meta charset="UTF-8" />
<style type="text/css">
.sec1{
height: 180px;
width: 180px;
@santanup789
santanup789 / functions.php
Last active February 14, 2020 09:46
Get total sale by product amount in woocommerce
<?php
function dw_product_totals() {
global $wpdb;
$post = get_post( $post_id );
$current_product = get_the_ID($post);
$order_items = apply_filters( 'woocommerce_reports_top_earners_order_items', $wpdb->get_results( "
@santanup789
santanup789 / ajaxsfilter.js
Last active September 22, 2023 21:44
Woocommerce product multiple term checkbox filtering by simple ajax [category + color + price]
jQuery(function($){
$('#filter').change(function(){
var filter = $('#filter');
$.ajax({
url:filter.attr('action'),
data:filter.serialize(), // form data
type:filter.attr('method'), // POST
beforeSend:function(xhr){
//filter.find('button').text('Processing...'); // changing the button label
$('#appendTable').html('<label class="alert">Processing...</label>');
@santanup789
santanup789 / get_child_parent_page.php
Created February 2, 2021 12:50
Get child pages of the current page, similarly get details of siblings of a child page along with the details of their parent page in a child page.
<?php
global $post;
$args = array(
'post_type' => 'page', //write slug of post type
'posts_per_page' => -1,
'post_parent' => $post->ID, //place here id of your parent page
'order' => 'ASC',
'orderby' => 'menu_order',
);
@santanup789
santanup789 / get_location_data.html
Last active February 3, 2021 14:59
Get data from IP for website
<div id='long'></div>
<div id='long'></div>
<pre id="response"></pre>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$.get("https://api.ipdata.co/?api-key=test", function (response) {
$("#response").html(JSON.stringify(response, null, 4));
$("#long").html(response.latitude + ", " + response.longitude);
$("#long").html(response.city + ", " + response.longitude);
@santanup789
santanup789 / functions.php
Created March 10, 2021 12:43
Wordpress Ajax Search post, custom post type anything.
//Place this code in functions.php
//add the ajax fetch js
add_action( 'wp_footer', 'ajax_fetch' );
function ajax_fetch() {
?>
<script type="text/javascript">
function fetch(){
jQuery.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
@santanup789
santanup789 / functions.php
Created May 19, 2021 11:52
Woocommerce AJAX product search [excluded catalog hidden products]
add_action('wp_footer', 'ajax_product_fetch');
function ajax_product_fetch()
{
?>
<script type="text/javascript">
function product_fetch() {
jQuery.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'post',
data: {action: 'product_fetch', product_keyword: jQuery('#product_keyword').val()},
@santanup789
santanup789 / get_child_parent__siblings_page.php
Created May 20, 2021 08:50
Get grand child pages, sub child pages along with siblings of parents of the current page using page depth calculation
<?php
global $post;
function get_all_subpages($page, $args = '', $output = OBJECT) {
// Validate 'page' parameter
if (! is_numeric($page))
$page = 0;
// Set up args
$default_args = array(
'post_type' => 'page',
@santanup789
santanup789 / functions.php
Created May 31, 2021 06:02
Filter Custom Post Types by Taxonomy in WP Admin Dashboard
<?php
add_action( 'restrict_manage_posts', 'filter_backend_by_taxonomies' , 99, 2);
/* Filter CPT via Custom Taxonomy */
/* https://generatewp.com/filtering-posts-by-taxonomies-in-the-dashboard/ */
function filter_backend_by_taxonomies( $post_type, $which ) {
// Apply this to a specific CPT
if ( 'team' !== $post_type )
return;
@santanup789
santanup789 / sort_by.php
Created June 18, 2021 11:21
WooCommerce custom product sort by code
<div class="wrapper-dropdown">
<form class="woocommerce-ordering" method="get">
<select name="orderby" class="orderby filter_orderby" aria-label="Shop order">
<?php
$catalog_orderby = apply_filters( 'woocommerce_catalog_orderby', array(
'menu_order' => __( 'Default sorting', 'woocommerce' ),
'popularity' => __( 'Sort by popularity', 'woocommerce' ),
'rating' => __( 'Sort by average rating', 'woocommerce' ),