Skip to content

Instantly share code, notes, and snippets.

View mahdiyazdani's full-sized avatar
:bowtie:
Still Rocking!

Mahdi Yazdani mahdiyazdani

:bowtie:
Still Rocking!
View GitHub Profile
@mahdiyazdani
mahdiyazdani / woocommerce-vacation-schedules.js
Last active March 16, 2024 18:49
Get WooCommerce vacation schedules via REST-API
import apiFetch from '@wordpress/api-fetch';
// Define your WooCommerce consumer key and secret
const consumerKey = 'your_consumer_key';
const consumerSecret = 'your_consumer_secret';
const storeUrl = 'https://your-domain.com/wp-json/store-vacation/v1';
// Function to fetch WooCommerce vacation schedules.
const fetchVacationSchedules = async () => {
try {
@mahdiyazdani
mahdiyazdani / add-custom-fields-in-user-registration-woocommerce.php
Last active February 22, 2024 13:55
Add custom fields in user registration WooCommerce
<?php
/**
* Displaying first name and last name fields on
* WooCommerce's registration page.
*/
function woocommerce_register_form() {
$fields = array(
'first_name' => __('First name', 'woocommerce'),
@mahdiyazdani
mahdiyazdani / get-dynamic-sidebar.php
Created February 1, 2018 13:12
Since there is NO "get_dynamic_sidebar" in the core, to return sidebar content instead of echoing out use the method below.
<?php
/**
* Gets the sidebar content based on given sidebar ID.
*
* @link https://forums.envato.com/t/get-dynamic-sidebar/76169/3?u=mypreview
* @param string $id ID of required registered sidebar.
* @return string|html The content of sidebar returned with HTML markup without "echo".
*/
if ( ! function_exists( 'prefix_get_dynamic_sidebar' ) ) :
@mahdiyazdani
mahdiyazdani / add-confirm-password-field-into-woocommerce-registration-form.php
Created October 8, 2016 19:26
Add confirm password field into WooCommerce registration form
<?php
/**
* Add the code below to your theme's functions.php file
* to add a confirm password field on the register form under My Accounts.
*/
function woocommerce_registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
global $woocommerce;
extract( $_POST );
if ( strcmp( $password, $password2 ) !== 0 ) {
@mahdiyazdani
mahdiyazdani / use-window-dimensions-react-hook.js
Created June 21, 2021 20:59
useWindowDimensions React Hook
import React from 'react';
import ReactDOM from 'react-dom';
function useWindowDimensions() {
const [width, setWidth] = React.useState(window.innerWidth);
const [height, setHeight] = React.useState(window.innerHeight);
React.useEffect(() => {
const handleResize = () => {
setWidth(window.innerWidth);
@mahdiyazdani
mahdiyazdani / use-wait-react-hook.js
Created June 21, 2021 20:29
useWait React Hook
import React from 'react';
import ReactDOM from 'react-dom';
function useWait(delay) {
const [status, setStatus] = React.useState(false);
React.useEffect(() => {
const id = window.setTimeout(() => {
setStatus((c) => !c);
}, delay);
@mahdiyazdani
mahdiyazdani / meal-maker-javascript.js
Created September 18, 2018 17:17
Meal Maker in JavaScript
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: []
},
addDishToCourse( courseName, dishName, dishPrice ) {
dish = {
name: dishName,
price: dishPrice
@mahdiyazdani
mahdiyazdani / remove-add-to-cart-variable-products.css
Created December 20, 2020 10:43
Remove add to cart button from variable products when "Store Vacation PRO" is activated
.wsvpro + .product form.cart {
display: none;
}
@mahdiyazdani
mahdiyazdani / fetch-data-with-useeffect.js
Created November 27, 2020 14:31
Fetch and display data with `useEffect`
// 1. Destructure the `subreddit` from props:
function Reddit({ subreddit }) {
const [posts, setPosts] = useState([]);
useEffect(() => {
async function fetchData() {
// 2. Use a template string to set the URL:
const res = await fetch(
`https://www.reddit.com/r/${subreddit}.json`
);
@mahdiyazdani
mahdiyazdani / render-once-useeffect.js
Created November 27, 2020 14:24
Focus an input control upon first render, using `useEffect` combined with the `useRef` hook
import React, { useEffect, useState, useRef } from "react";
import ReactDOM from "react-dom";
function App() {
// Store a reference to the input's DOM node
const inputRef = useRef();
const [value, setValue] = useState("");
useEffect(
() => {