Skip to content

Instantly share code, notes, and snippets.

View dev-w3's full-sized avatar
💻
Working from home

W3use dev-w3

💻
Working from home
View GitHub Profile
@dev-w3
dev-w3 / comparetime.php
Created September 27, 2022 09:18
change default timezone and check if current time is between two time
<?php
$estTime = (new DateTime('America/New_York'))->format('h:i a');
$current_time = $estTime;
$sunrise = "12:00 am";
$sunset = "03:00 am";
$date1 = DateTime::createFromFormat('h:i a', $current_time);
$date2 = DateTime::createFromFormat('h:i a', $sunrise);
$date3 = DateTime::createFromFormat('h:i a', $sunset);
if ($date1 > $date2 && $date1 < $date3)
{
@dev-w3
dev-w3 / hidepaymentmethod.php
Last active July 21, 2021 09:06
To hide payment method if coupon is applied in woo-commerce
<?php
add_filter('woocommerce_available_payment_gateways', '_hide_payment_gateways', 20, 1 );
function _hide_payment_gateways( $available_gateways){
// Not in backend (admin)
if( is_admin() )
return $available_gateways;
// If at least a coupon is applied
if( sizeof( WC()->cart->get_applied_coupons() ) > 0 ){
<?php
## Function to set file permissions to 0644 and folder permissions to 0755
function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){
$d = new RecursiveDirectoryIterator( $dir );
foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
if( $path->isDir() ) chmod( $path, $dirModes );
else if( is_file( $path ) ) chmod( $path, $fileModes );
}
@dev-w3
dev-w3 / wix.js
Last active July 21, 2021 09:09
Wix - Velo: Accessing 3rd-Party Services with the Fetch API
// API Reference: https://www.wix.com/velo/reference/api-overview/introduction
// “Hello, World!” Example: https://learn-code.wix.com/en/article/1-hello-world
import wixData from 'wix-data';
import { getJSON } from 'wix-fetch';
import {local} from 'wix-storage';
export function getrentallistings () {
const mySecret = 'key_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
<?php
$curl = curl_init('https://www.domain.com/outwell/posadas-foldaway-bed-single');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$page = curl_exec($curl);
$related_products = array();
// Get Content Inside of productdetail_lblProductName Div/ Regex Match
$regex = '/<div id="productdetail_lblProductName">(.*?)<\/div>/s';
@dev-w3
dev-w3 / getalllinks.php
Created March 10, 2021 09:49
Get All href link from third party URL
add_action( 'rest_api_init', 'register_api_hooks' );
add_action( 'rest_api_init', 'wp_rest_user_endpoints' );
function register_api_hooks() {
register_rest_route(
'apihandle/', '/login/',
array(
'methods' => 'POST',
'callback' => 'login_api',
@dev-w3
dev-w3 / isVisible.js
Created March 13, 2020 07:06
jQuery event to trigger action when a Element is made visible
jQuery(document).ready(function ($) {
let alreadyThere = false;
$.fn.isVisible = function (topSet = 0) {
_this = $(this);
_this = (typeof _this == 'object' || typeof _this == 'function') ? _this.get(0) : _this;
const rect = _this.getBoundingClientRect();
return (
rect.bottom >= 0 &&
@dev-w3
dev-w3 / CSVmanager.php
Last active April 12, 2024 17:37
CSV Manager for WP Store Locator
<?php
#CSV Manager for WP Store Locator
#https://wordpress.org/plugins/wp-store-locator/
// Redirect to 404 if script is accessed directly
if ( ! defined("ABSPATH") ) {
header("Location: http://{$_SERVER['HTTP_HOST']}/404");
die;
};
@dev-w3
dev-w3 / tabbed-description.liquid
Last active March 13, 2020 07:10
Shopify: Tabs for product descriptions
{% comment %}
if combine_pretext is false, the text before the first <h6> will be shown above all tabs, otherwise added to the first tab
{% endcomment %}
{% assign combine_pretext = false %}
{% assign description = tabbed-description | default: product.description %}
{% if description contains "<h6>" %}
{% assign tab_heads = '' %}
{% assign tab_texts = '' %}
{% assign pretext = '' %}