Skip to content

Instantly share code, notes, and snippets.

@wpflames
wpflames / card.scss
Created February 17, 2023 16:37
Display child pages with featured images in cards
.card {
background: transparent;
box-shadow: var(--shadow-1);
border: 1px solid var(--grey-100);
color: var(--grey-800);
transition: var(--ease);
&:hover .card-figure-overlay {
opacity: 1;
}
&:hover .card-title {
@wpflames
wpflames / custom-checkbox.php
Created February 16, 2023 14:44
Add discount checkbox field to WooCommerce checkout, save meta data, display in admin and in email
<?php
// Add a custom checkbox fields after billing fields
add_action( 'woocommerce_before_order_notes', 'add_custom_checkout_checkbox', 20 );
function add_custom_checkout_checkbox(){
// Add a custom checkbox field
if (ICL_LANGUAGE_CODE == "hu") {
woocommerce_form_field( 'discount_for_members', array(
'type' => 'checkbox',
@wpflames
wpflames / extra-fee.php
Created February 16, 2023 13:04
Add extra fee to COD payment gateway
<?php
// =========================================================================
// ADD EXTRA FEE TO SPECIFIC PAYMENT GATEWAY => COD
// =========================================================================
// Part 1: assign fee
function add_checkout_fee_for_gateway() {
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Check if there are non-virtual products
$chosen_gateway = WC()->session->chosen_payment_method;
if ( $chosen_gateway == 'cod' ) {
@wpflames
wpflames / Spinner.js
Created February 7, 2023 13:44
React - Spinner Component
import React, { Fragment } from 'react';
import spinner from '../../assets/images/spinner.gif';
const Spinner = () => (
<Fragment>
<img
src={spinner}
alt='Loading...'
style={{ width: '200px', margin: 'auto', display: 'block' }}
/>
@wpflames
wpflames / App.js
Created February 7, 2023 12:53
React HTTP Request with Axios
import React, { Fragment, Component } from 'react';
import Navbar from './components/layout/Navbar';
import Users from './components/users/Users';
import axios from 'axios';
import './App.css';
class App extends Component {
state = {
users: [],
loading: false,
@wpflames
wpflames / Navbar.js
Created February 7, 2023 11:56
Stateless functional components
import React from 'react';
import PropTypes from 'prop-types';
const Navbar = ({ icon, title }) => {
return (
<nav className='navbar bg-primary'>
<h1>
<i className={icon} /> {title}
</h1>
</nav>
@wpflames
wpflames / Users.js
Created February 7, 2023 11:39
React - Passing state with props
import React, { Component } from 'react';
import UserItem from './UserItem';
class Users extends Component {
state = {
users: [
{
id: '1',
login: 'gabor',
avatar_url: 'https://avatars.githubusercontent.com/u/70385943?v=4',
@wpflames
wpflames / tab.js
Last active December 14, 2022 10:03
Tab Panel with JavaScript
function openTab(evt, tabName) {
// Declare all variables
var i, tabcontent, tablinks;
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
@wpflames
wpflames / option-pages.scss
Created December 4, 2022 21:05
ACF Option Pages with Repeater Group and File
.download{
width: 100%;
margin: 60px auto;
&-item{
display: flex;
justify-content: space-between;
text-decoration: none;
color: var(--black);
transition: $ease;
text-decoration: underline;
@wpflames
wpflames / option-pages.php
Last active December 4, 2022 21:05
ACF Option Pages with Repeater Group and File
<!-- Repeater / Group / File -->
<div class="download">
<?php if( have_rows('download_repeater', 'option') ): ?>
<?php while( have_rows('download_repeater', 'option') ): the_row(); ?>
<?php if( have_rows('download_group', 'option') ): ?>
<?php while( have_rows('download_group', 'option') ): the_row();
$title = get_sub_field('title', 'option');