Skip to content

Instantly share code, notes, and snippets.

View santanup789's full-sized avatar

Santanu Patra santanup789

  • Webskitters
  • India
View GitHub Profile
@santanup789
santanup789 / functions.php
Last active January 5, 2022 10:57
Add woocommerce product categories after shop loop item title using woocommerce hook
<?php
//add Product category and number of flavour attribute after shop loop title
add_filter( 'woocommerce_after_shop_loop_item_title', 'so58344618_variation_count' );
function so58344618_variation_count() {
global $product;
$categories = get_the_terms( $post->ID, 'product_cat' );
$catList = '';
foreach($categories as $category) {
if(!empty($catList)) {
@santanup789
santanup789 / archive_list.php
Created December 9, 2021 06:08
List down the available archive options like year month etc in a select dropdown or in normal div format with active link to redirect
<!--<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value=""><?php //esc_attr( _e( 'Select Month', 'textdomain' ) ); ?></option> -->
<?php wp_get_archives( array(
'post_type' => 'afr-news',
'type' => 'yearly', // monthly
'format' => 'custom', // option
'before' => '<div class="sub-item">',
'after' => '</div>',
'show_post_count' => 0 // 1
) );
@santanup789
santanup789 / googlemap.php
Created October 29, 2021 11:10
Dynamic Google map with multiple marker information managed with ACF WordPress Plugin
<?php
<script src="https://maps.googleapis.com/maps/api/js?key=<?php the_field('gmap_api_key', 'option'); ?>"></script>
<style>
.acf-map { height: 600px; }
p.emails a:not(:last-child)::after {
content: ', ';
}
</style>
<div class="acf-map">
<?php while ( have_rows('locations') ) : the_row();
@santanup789
santanup789 / googlemap.php
Created October 27, 2021 13:59
Stylish Google map show with dynamic field feature of ACF and also with multiple location pointers and pointer information.
<?php
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=<?php the_field('gmap_api_key', 'option'); ?>"></script>
<style type="text/css">
#map {
width: 100%;
height: 600px;
}
</style>
@santanup789
santanup789 / functions.php
Created October 6, 2021 10:03
Display woocommerce product category title and description on the shop page on page load after filtering the products or ajax product filter. In both system it will work.
<?php
add_action('woocommerce_before_shop_loop', 'show_category_title', 10, 2);
function show_category_title() {
$cat_title = single_tag_title("", false);
$cat_description = tag_description("", false);
echo '<div class="all_notice">'<h2>' . $cat_title .'</h2><p>' . $cat_description . '</p></div>';
}
?>
@santanup789
santanup789 / functions.php
Created September 23, 2021 09:22
Hook for elementor to not load some css or js on the builder preview page
<?php
function footerCondition() {
// Not in edit mode
if ( ! \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
?>
<script>
jQuery(function($){
var footerHeight = $('.elementor.elementor-location-footer').height();
$('.site-main section.elementor-top-section:last-child').css('padding-bottom', footerHeight);
$('.elementor.elementor-location-footer').css('margin-top', -footerHeight);
@santanup789
santanup789 / functions.php
Created September 23, 2021 09:19
Filter wp_nav_menu() to add additional links and other output
<?php
// Filter wp_nav_menu() to add additional links and other output
function new_nav_menu_items($items) {
if(!is_page(28)) {
$homelink = '<li class="home menu-item menu-item-type-custom menu-item-object-custom menu-item-009"><a href="' . get_permalink( 28 ) . '#bwe-showreel" class="elementor-item elementor-item-anchor">Showreel</a></li>';
}
else {
$homelink = '<li class="home menu-item menu-item-type-custom menu-item-object-custom menu-item-009"><a href="#bwe-showreel" class="elementor-item elementor-item-anchor">Showreel</a></li>';
}
// add the home link to the end of the menu
@santanup789
santanup789 / functions.php
Created September 23, 2021 09:14
Making a custom loader screen for wordpress site with conditions.
<?php
function footerCondition() {
// Not in edit mode
if ( ! is_user_logged_in() ) {
?>
<div id='load' class="loader">
<div class='loader-content'>
<h2>Welcome to </h2>
<svg id="svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400" height="130.6122448979592" viewBox="0, 0, 400,130.6122448979592"><g id="svgg"><path id="path0" d="M27.974 3.612 C 24.011 11.963,13.678 21.020,5.226 23.553 L 0.943 24.836 1.237 33.081 L 1.531 41.327 6.904 41.282 C 13.710 41.226,16.052 39.067,17.891 31.156 C 20.765 18.793,31.470 11.335,38.325 16.920 C 40.277 18.510,40.276 18.522,38.265 17.729 C 28.022 13.687,23.508 19.238,23.481 35.911 L 23.469 42.740 27.806 43.130 L 32.143 43.521 27.806 43.699 L 23.469 43.878 23.469 50.510 C 23.469 57.800,23.540 57.862,29.182 55.504 C 37.779 51.912,49.462 56.289,53.489 64.610 L 56.048 69.898 56.085 34.949 L 56.122 0.000 42.905 -0.000 L 29.688 -0.000 27.974 3.612 M104.709 27.641 C 100.800 30.716,99.176 34.493,98.800 41.385 L 98.469 4
@santanup789
santanup789 / post_archive_loop.php
Created August 26, 2021 10:02
Get post for archive page with featured image, category name, post date, author name, short description, title, read more link and if you have youtube video url custom field for each post that is also done. Also fancyapps lightbox for youtube video player with pagination.
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$default_posts_per_page = get_option( 'posts_per_page' );
$args = array (
'post_type' => 'post',
'posts_per_page' => -1,
'posts_per_page' => $default_posts_per_page,
'paged' => $paged,
'tax_query' => array( array(
'taxonomy' => 'category',
@santanup789
santanup789 / functions.php
Created August 23, 2021 08:27
Add Custom link or text in view order page under user's my account page in WooCommerce for a particular page
//Providing the Gold pack download link on view order page under my account page.
add_action( 'woocommerce_view_order', 'before_woocommerce_order_details', 5 );
function before_woocommerce_order_details($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: 20px;padding: 20px;margin-bottom: 30px; color: #fff;">In this order, you have purchased <a href="h#" 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>';