Skip to content

Instantly share code, notes, and snippets.

View ibrahim-kardi's full-sized avatar

Mohammad Ibrahim ibrahim-kardi

View GitHub Profile
@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;
}
}
@ibrahim-kardi
ibrahim-kardi / gist:ccb671f1deb27e5f2a15680e007f81c7
Created July 7, 2023 07:53
override specific gutenberg block function
if (has_block("gallery", get_the_content()))
{
$post_blocks = parse_blocks(get_the_content());
foreach ($post_blocks as $post_block)
{
if ("core/gallery" == $post_block["blockName"])
{
$ids = $post_block["attrs"]["ids"];
}
}
@ibrahim-kardi
ibrahim-kardi / gist:707dca5a00574753fcec16b397cc8101
Created June 23, 2023 10:46
get woocommerce state under the country
$valid_states = WC()->countries->get_states( $country );
$for_country = isset( $args['country'] ) ? $args['country'] : WC()->checkout->get_value( 'billing_state' === $key ? 'billing_country' : 'shipping_country' );
$states = WC()->countries->get_states( $for_country );