Skip to content

Instantly share code, notes, and snippets.

View wprashed's full-sized avatar
🏃‍♂️
Being More Productive

Rashed Hossain wprashed

🏃‍♂️
Being More Productive
View GitHub Profile
@wprashed
wprashed / functions.php
Created May 13, 2025 07:21
This code tracks recently viewed products using cookies and displays them on the single product page using a shortcode. It hooks into woocommerce_after_single_product to show the products below product details.
// Track recently viewed products
function track_recently_viewed_products() {
if (is_singular('product')) {
$product_id = get_the_ID();
// Get current list from cookie
$recently_viewed = isset($_COOKIE['recently_viewed_products']) ? explode(',', $_COOKIE['recently_viewed_products']) : [];
// Remove current product if already exists
if (($key = array_search($product_id, $recently_viewed)) !== false) {
@wprashed
wprashed / functions.php
Created May 13, 2025 07:18
This code snippet to show a live stock countdown message like “Only 3 left!” on the product page when stock quantity is low.
// Show live stock countdown message
function rh_live_stock_countdown_message() {
global $product;
// Set the threshold for low stock
$stock_threshold = 5;
// For variable products
if ( $product->is_type( 'variable' ) ) {
echo '<div id="rh-stock-count-message"></div>';
@wprashed
wprashed / product-qa-section.php
Created May 9, 2025 06:17
Adds a Q&A section to WooCommerce product pages.
// 1. Add a new tab to product pages
add_filter( 'woocommerce_product_tabs', function( $tabs ) {
$tabs['qa_tab'] = [
'title' => 'Q&A',
'priority' => 50,
'callback' => 'render_product_qa_tab',
];
return $tabs;
});
@wprashed
wprashed / guest-checkout-reminder.php
Created May 6, 2025 07:28
Shows a reminder for guest users to register after completing a purchase.
add_action('woocommerce_thankyou', 'gcr_show_guest_reminder_notice');
function gcr_show_guest_reminder_notice($order_id) {
if (is_user_logged_in()) {
return; // Logged-in users don't need the reminder
}
$order = wc_get_order($order_id);
if (!$order) return;
@wprashed
wprashed / sticky-checkout-button.php
Created May 6, 2025 07:26
Adds a sticky "Proceed to Checkout" or "Place Order" button on cart and checkout pages.
add_action('wp_footer', 'scb_add_sticky_button');
function scb_add_sticky_button() {
if (!is_cart() && !is_checkout()) return;
?>
<style>
.scb-sticky-btn {
position: fixed;
bottom: 0;
@wprashed
wprashed / functions.php
Created May 6, 2025 07:21
Here's a simple "Mini Cart in Header" implementation for your WooCommerce site using a shortcode + hook. This will: Display a mini cart icon with item count and subtotal in the header. Show a dropdown cart when hovered or clicked (you can customize this behavior). Use basic WooCommerce functions.
// Add Mini Cart to header via hook
add_action('wp_head', 'rashed_enqueue_mini_cart_styles');
add_action('wp_footer', 'rashed_enqueue_mini_cart_script');
function rashed_enqueue_mini_cart_styles() {
?>
<style>
.rashed-mini-cart {
position: relative;
display: inline-block;
@wprashed
wprashed / save_cart.php
Created May 6, 2025 07:19
This code saves the user's cart when they leave the site and restores it automatically when they return — even for guest users, using cookies.
// Save cart contents to cookie on page unload
function rashed_save_cart_to_cookie() {
if ( is_admin() || is_cart() || is_checkout() ) return;
?>
<script type="text/javascript">
window.addEventListener('beforeunload', function () {
if (typeof wc_cart_params === 'undefined') return;
fetch(wc_cart_params.ajax_url + '?action=rashed_get_cart_contents', {
@wprashed
wprashed / one-click-checkout.php
Created May 6, 2025 07:17
Adds a "Buy Now" button to product pages that skips the cart and goes directly to checkout.
// Add Buy Now button next to Add to Cart
add_action('woocommerce_after_add_to_cart_button', 'one_click_checkout_button');
function one_click_checkout_button() {
global $product;
if ($product->is_type('simple')) {
$url = esc_url(add_query_arg([
'one_click_checkout' => 'yes',
'product_id' => $product->get_id()
], home_url()));
# 1. Variables and Data Types
name = "Rashed"
age = 25
is_student = True
print("Name:", name)
print("Age:", age)
print("Is Student:", is_student)
print("Type of name:", type(name))
import os
from PIL import Image
# Input and output directories
INPUT_FOLDER = "input_images"
OUTPUT_FOLDER = "output_images"
NEW_SIZE = (4000, 2250) # Set your desired width and height
# Create output folder if it doesn't exist
os.makedirs(OUTPUT_FOLDER, exist_ok=True)