Skip to content

Instantly share code, notes, and snippets.

View ibrahim-kardi's full-sized avatar

Mohammad Ibrahim ibrahim-kardi

  • Mirpur, Dhaka -1216,Bangladesh
View GitHub Profile
@ibrahim-kardi
ibrahim-kardi / n-stock-products
Created May 12, 2025 10:55
In stock woocommerce products list API endpoint
add_action('rest_api_init', function () {
register_rest_route('custom/v1', '/in-stock-products', array(
'methods' => 'GET',
'callback' => 'get_in_stock_products',
'permission_callback' => '__return_true',
));
});
function get_in_stock_products() {
$args = [
@ibrahim-kardi
ibrahim-kardi / deploy.yml
Created April 30, 2025 18:22
Auto Deploy to WordPress.org
name: Deploy to WordPress.org
on:
push:
tags:
- "*"
jobs:
tag:
name: New tag
runs-on: ubuntu-latest
steps:
@ibrahim-kardi
ibrahim-kardi / function.php
Created July 10, 2024 11:03
woocommerce_account_menu_items add custom menu item
// Check if the user has purchased specific product IDs
function user_has_purchased_product($user_id, $product_ids) {
// Get all orders for the user
$customer_orders = wc_get_orders(array(
'customer_id' => $user_id,
'status' => array('completed', 'processing', 'on-hold')
));
// Loop through orders and check if the product is purchased
foreach ($customer_orders as $order) {
@ibrahim-kardi
ibrahim-kardi / gist:0788baced1b27f80b82a7896c8d63a2f
Created January 26, 2024 11:20
Load delay any section by CSS
@keyframes delay {
0% { opacity: 0; }
100% { opacity: 1; }
}
/* Apply animation to the section */
section {
opacity: 0; /* Initially hide the section */
animation: delay 2s ease forwards; /* Apply animation with 2-second delay */
}
<div class="slider">
<div>
<div class="text">
This is the worst kind of discrimination: the kind against me! You don't know how to do any of those. You are the last hope of the universe. Yes, except the Dave Matthews Band doesn't rock.
</div>
</div>
<div>
<div class="text">
This is the worst kind of discrimination: the kind against me! You don't know how to do any of those. You are the last hope of the universe. Yes, except the Dave Matthews Band doesn't rock.
</div>
@ibrahim-kardi
ibrahim-kardi / gist:4fb0d018864772bce6ea436ba194b94a
Created November 4, 2023 17:58
how to handle currency switcher
window.addEventlistener(DOMcontentloaded,()=>{
function currencyFormhandler(event){
event.target.form.submit();
}
document.querySelectorAll(.selecclass).forEach((elm)=>{
elm.addEventlistener('change'.currencyFormhandler)
})
})
@ibrahim-kardi
ibrahim-kardi / docker-compose.yaml
Created November 1, 2023 17:24
Docker with WordPress
# YAML is a human-readable data-serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted.
version: '3.1' # Compose file versions
services:
#Database
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
<?php
/**
* Plugin Name: Demo Plugin
* Plugin URI: https://smalltowndev.com
* Description: A demo plugin to show how to WordPress.
* Author: kardi
* Version: 1.0.0
* Author URI: https://kardi.com
*
* @package wordpress-reset
@ibrahim-kardi
ibrahim-kardi / gist:54d23c88047cdadcd260d66613d12916
Created August 19, 2023 06:53
Registers wordpress dashboard widget
<?php
add_action( 'wp_dashboard_setup', 'test_dashboard_widget' );
/**
* Registers dashboard widget.
*/
function test_dashboard_widget() {
wp_add_dashboard_widget(
'test_dashboard_widget',
esc_html( 'Test widget' ),
add_filter(
'user_has_cap',
function( $allcaps, $caps, $args, WP_User $user ) {
$current_user = wp_get_current_user();
$requested_cap = $args[0];
if ( $user->ID === $current_user->ID && in_array( 'customer', (array) $current_user->roles ) ) {
if ( 'upload_files' === $requested_cap ) {
return $allcaps;
}
}