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 / 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 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' ),
@santanup789
santanup789 / youtube_details.php
Created July 2, 2021 06:57
Get Youtube video thumbnail and title dynamically using video ID
<?php
$get_yt_url = 'https://www.youtube.com/watch?v=VaSstf9VJGQ';
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $get_yt_url, $match);
$youtube_id = $match[1];
echo "<img src='https://img.youtube.com/vi/$youtube_id/maxresdefault.jpg' alt='$getTitle'>";
//Get youtube video title dynamically
echo explode(' - YouTube',explode('</title>',explode('<title>',file_get_contents("https://www.youtube.com/watch?v=$youtube_id"))[1])[0])[0];
@santanup789
santanup789 / functions.php
Created August 23, 2021 08:23
Add custom link on WooCoommerce Received page for a particular product purchase and if the order status is processing or completed.
//Providing the Gold pack download link on the order receive page.
add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 );
function woo_change_order_received_text( $str, $order_id ) {
$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item_id => $item ) {
$product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
if ( $product_id === 8936 ) {
if( $order->get_status() == 'processing' || $order->get_status() == 'completed' ) {
echo '<h3 style="background: #70C0AD;font-size: 24px;padding: 20px;margin-bottom: 30px; color: #fff;">You have successfully purchased <a href="#" target="_bkank" style="Color: #000; font-weight: bold;">Kidney Solution Gold Pack</a>. Please download the package from <a href="#" target="_bkank" style="Color: #000; font-weight: bold;">HERE</a>.</h3>';