Skip to content

Instantly share code, notes, and snippets.

View emre-edu-tech's full-sized avatar

Media Pons emre-edu-tech

View GitHub Profile
@emre-edu-tech
emre-edu-tech / app.css
Last active February 5, 2020 11:12
Using CSS box-shadow property to simulate 'border' property and 'border-collapse: collapse' behaviour
box-shadow: 3px 0 0 0 #000,
0 3px 0 0 #000,
3px 3px 0 0 #000,
3px 0 0 0 #000 inset,
0 3px 0 0 #000 inset;
@emre-edu-tech
emre-edu-tech / functions.php
Last active August 12, 2020 07:17
This is a Wordpress code snippet to check the user's country and show them as a warning using SweetAlert2. Warning was shown on Checkout page in this example.
function get_user_geo_country(){
if(is_checkout()) {
$geo = new WC_Geolocation(); // Get WC_Geolocation instance object
$user_ip = $geo->get_ip_address(); // Get user IP
$user_geo = $geo->geolocate_ip( $user_ip ); // Get geolocated user data.
$country = $user_geo['country']; // Get the country code
if($country != 'DE') {
?>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<script>
@emre-edu-tech
emre-edu-tech / scope-hoisting.js
Created September 1, 2020 06:21
This example shows the importance of Javascript hoisting.
let result = 1;
// here this declaration must come first before using it
// it is a function variable declaration so it should be declared before its usage
const addNumber = function (numToAdd) {
result = result + numToAdd;
return result;
}
let baseNumber = 10;
addAnotherNumber(5);
baseNumber = 20;
// function closures have access to variable NAMES not the VALUES
// value is only checked when the function runs
function addAnotherNumber(num) {
setTimeout(function() {
@emre-edu-tech
emre-edu-tech / basic-promise.js
Last active September 1, 2020 09:19
This is a simple demonstration of how then()-catch() methods work while heading an api. We can see clearly then() methods are called after the previous promise resolve.
// Here every then() method returns a new promise
// then() method always yields a promise after being executed, this way chaining is possible
// We can say here that every then() methods waits the previous promise to resolve
// Here the error handling is also easy. If any prior promise fails, catch() method will be triggered
fetch('https://api.openweathermap.org/data/2.5/weather?q=London,uk')
.then(response => {
return response.json();
})
.then(data => {
console.log(data);
@emre-edu-tech
emre-edu-tech / functions.php
Last active September 24, 2020 09:52
This is a Custom Wordpress Nav Walker implementation for a custom Bootstrap Menu.
<?php
// So-called menu is below and we will implement this custom menu by extending Walker_Nav_Menu class
/*
<ul>
<li class="active"><a href="index.html">Home</a></li>
<li class="drop-down"><a href="">About</a>
<ul>
<li><a href="about.html">About Us</a></li>
<li><a href="team.html">Team</a></li>
<li><a href="testimonials.html">Testimonials</a></li>
@emre-edu-tech
emre-edu-tech / functions.php
Last active September 24, 2020 10:20
This is a demonstration of how to add favicons in custom wordpress theme using functions.php
<?php
//It is not super complete but it is ok for the start
// Remember that $favicon_path will change according to your assets directory structure
function add_favicons() {
// declare the path variables
$favicon_path = get_template_directory_uri() . '/assets/img/favicon.ico';
$apple_touch_icon_72x72_path = get_template_directory_uri() . '/assets/img/apple-touch-icon-72x72.png';
$apple_touch_icon_114x114_path = get_template_directory_uri() . '/assets/img/apple-touch-icon-114x114.png';
// echo to the wp_head anchor to append to it
@emre-edu-tech
emre-edu-tech / functions.php
Created May 29, 2022 08:31
Woocommerce - Change add to cart button to custom button on product archive page
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_add_to_cart_button_on_product_archive', 10, 2 );
function replace_add_to_cart_button_on_product_archive($button, $product) {
$button_text = __("Show Product", "text_domain");
$button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
return $button;
}
@emre-edu-tech
emre-edu-tech / functions.php
Created May 29, 2022 08:35
Woocommerce - Replace add to cart button with custom button on Single Product Template
add_action( 'woocommerce_single_product_summary', 'replace_single_add_to_cart_button', 1 );
function custom_product_button(){
$product = wc_get_product();
// HERE your custom button text and link
$button_text = __( "Im Leoshop kaufen", "the7dt-child" );
// Display button
echo '<a class="button" style="text-align: center; margin-bottom: 10px;" target="_blank" href="'.get_field('external_product_link', $product->get_id()).'">' . $button_text . '</a>';
}
@emre-edu-tech
emre-edu-tech / theme.json
Last active April 14, 2023 07:29
Wordpress Full Site Editor theme.json sample file with a Visual Studio Code Schema - Theme Prefix is devforwp
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"typography": {
"fontFamilies": [
{ "fontFamily": "Rubik, sans-serif", "slug": "devforwp-rubik", "name": "DevForWp Rubik" }
],
"fontSizes": [
{ "slug": "small", "size": "0.75rem", "name": "Small" },