Skip to content

Instantly share code, notes, and snippets.

View anisur2805's full-sized avatar
🎯
Focusing

Anisur Rahman anisur2805

🎯
Focusing
View GitHub Profile
@anisur2805
anisur2805 / index.html
Created February 10, 2024 15:18
Upload image and preview image
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Upload and Preview Image</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input
@anisur2805
anisur2805 / index.php
Created February 8, 2024 09:09
Customize the product titles displayed on the WooCommerce Cart page by incorporating additional custom elements.
<?php
/*
Preview image: https://i.imgur.com/5FxW6x3.png
This is for modify the product name in cart page.
*/
add_filter( 'woocommerce_product_title', 'cart_product_title', 20, 2 );
function cart_product_title( $title, $values ) {
return $title . ' extra cheese burger';
}
@anisur2805
anisur2805 / test.js
Last active February 10, 2024 15:21
test
import { createReduxStore, register } from '@wordpress/data';
export const DEFAULT_STATE = {
drag: {
source: 'panel', //null,
uid: null,
id: 'heading', //null, heading, container,
draggingNode: null,
},
isDragging: false,
@anisur2805
anisur2805 / index.html
Created January 3, 2024 16:23
JS Debouce example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" onkeyup="betterSearch()" id="name">
@anisur2805
anisur2805 / add_phone_email_to_single_product.php
Created December 28, 2023 17:51
WooCommerce Every product add custom email and phone number. If no one is provide will display default one on Single Product Page underneath Title
<?php
// Preview Backend: https://i.imgur.com/hyLOnlI.png
// Preview Frontend: https://i.imgur.com/hyLOnlI.png
// Add new tab in the backend.
add_filter( 'woocommerce_product_data_tabs', 'sfc_add_product_data_to_tab' );
function sfc_add_product_data_to_tab( $default_tabs ) {
global $post;
$tabs = array(
'sfc_phone_email' => array(
@anisur2805
anisur2805 / complex-sql-query.php
Last active December 25, 2023 05:57
Complex query with SQL
<?php
function get_order_meta_by_key3( $meta_key = 'order_status' ) {
// Check if the data is already cached.
$cache_key = 'order_meta_cache_' . $meta_key;
$cached_data = get_transient( $cache_key );
if ( false !== $cached_data ) {
return $cached_data;
@anisur2805
anisur2805 / rest-api.php
Created June 4, 2023 18:17
Create a very basic rest api
<?php
/**
* Plugin Name: Awesome API Test
* Description: Awesome Desc...
* Plugin URI: #
* Version: 1.0
* Author: #
* Author URI: http://github.com/anisur2805/
* Text Domain: test-domain
* License: GPL v2 or later
@anisur2805
anisur2805 / index.html
Created June 2, 2023 12:25
Create a link hover style
<ul>
<li><a href="">Item 1</a></li>
<li><a href="">Item two</a></li>
<li><a href="">Item three</a></li>
<li><a href="">Item4</a></li>
<li><a href="">Item5</a></li>
<li><a href="">Item6</a></li>
<li><a href="">Item7</a></li>
<li><a href="">Item8</a></li>
</ul>
@anisur2805
anisur2805 / index.php
Created June 2, 2023 03:13
Create a page template from plugin, sometimes we need to add a page template from our own plugin, this code will help to create.
<?php
function custom_template_include($template) {
if (is_page('test')) { // your desiger page
$new_template = IC_CORE_PATH . '/templates/custom-template.php'; // your desier file
if (file_exists($new_template)) {
return $new_template;
}
}
@anisur2805
anisur2805 / functions.php
Last active May 19, 2023 17:19
Gravity form category select field value was render as ID instead of name.
<?php
// Step #1:
// In this case the problem was i have a category/ taxonomy select field in gravity form and its value was id where as my requirement was use name. So i firstly use `gform_pre_render` filter hook to change the options value with name. My select field ID was 38.
add_filter( 'gform_pre_render', 'modify_select_field_options' );
function modify_select_field_options( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->type === 'select' && $field->id === 38 ) {
$categories = get_terms( array(
'taxonomy' => 'services-category',
'hide_empty' => false,