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 / uninstall-store-vacation.php
Created April 22, 2024 19:06
Delete Store Vacation Settings
<?php
delete_option( '_wsvpro_settings' );
// For site options in Multisite.
delete_site_option( '_wsvpro_settings' );
@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 / 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 / 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(
() => {
@mahdiyazdani
mahdiyazdani / float-to-string.php
Created November 1, 2020 22:48
Convert a float to a string without locale formatting
<?php
/**
* Convert a float to a string without locale formatting which PHP adds when changing floats to strings.
*
* @param float $float Float value to format.
* @return string
*/
function prefix_float_to_string( $float ) {
if ( ! is_float( $float ) ) {
@mahdiyazdani
mahdiyazdani / string-to-array.php
Created November 1, 2020 22:47
Explode a string into an array by delimiter
<?php
/**
* Explode a string into an array by $delimiter and remove empty values.
*
* @param string $string String to convert.
* @param string $delimiter Delimiter, defaults to ','.
* @return array
*/
function prefix_string_to_array( $string, $delimiter = ',' ) {
@mahdiyazdani
mahdiyazdani / wpml-config.xml
Created November 1, 2020 17:09
WPML language configuration file
<wpml-config>
<custom-fields>
<custom-field action="copy">quantity</custom-field>
<custom-field action="translate">custom-title</custom-field>
</custom-fields>
<custom-types>
<custom-type translate="1">book</custom-type>
<custom-type translate="1">DVD</custom-type>
</custom-types>
<taxonomies>