Skip to content

Instantly share code, notes, and snippets.

View freezvd's full-sized avatar

Valentin Zmaranda freezvd

  • Bucharest, Romania
View GitHub Profile
@freezvd
freezvd / core-blocks-list-cpt-register.php
Created March 25, 2022 13:41 — forked from marcelotorres/core-blocks-list-cpt-register.php
Gutenberg Templates: Core Blocks List in CPT register
<?php
[...]
'template' =>
array(
array('core/archives'),
array('core/audio'),
array('core/block'),
array('core/button'),
array('core/categories'),
@freezvd
freezvd / conditional-theme-json.php
Created March 23, 2022 09:34 — forked from ronalfy/conditional-theme-json.php
Conditionally Load theme.json
<?php
// Intended to go into functions.php of parent or child theme.
// Assumes directory structure of /theme-name/skins/folder-name/theme.json (see switch statement below).
/**
* Conditionally load the default theme.json file.
*
* @package coaching-pro
*/
@freezvd
freezvd / expect-header-fix.php
Created March 11, 2021 09:18 — forked from carlalexander/expect-header-fix.php
WordPress "Expect" header fix
<?php
/**
* By default, cURL sends the "Expect" header all the time which severely impacts
* performance. Instead, we'll send it if the body is larger than 1 mb like
* Guzzle does.
*/
function add_expect_header(array $arguments)
{
$arguments['headers']['expect'] = !empty($arguments['body']) && strlen($arguments['body']) > 1048576 ? '100-Continue' : '';
@freezvd
freezvd / customizer.php
Created December 13, 2018 09:03 — forked from purzlbaum/customizer.php
Google Font select for WordPress Customizer
<?php
new theme_customizer();
class theme_customizer {
public function __construct() {
add_action( 'customize_register', array(&$this, 'customize_linje' ));
}
/**
* Customizer manager demo
@freezvd
freezvd / post-type.php
Created October 7, 2018 10:35 — forked from forkbombe/post-type.php
An example of how to create a WordPress Custom Post type using an Object Oriented approach
<?php
/**
* Use namespace to avoid conflict
*/
namespace PostType;
/**
* Class Event
* @package PostType
*
@freezvd
freezvd / gf-map-class-to-post-meta.php
Created September 25, 2018 07:09 — forked from uamv/gf-map-class-to-post-meta.php
Save Gravity Form field data to post meta by adding a class to the field.
<?php
/**
* Save Gravity Form field data to post meta by adding a class to any field.
* Meta is mapped so that it is readable by Advanced Custom Fields
* Format class as…
* post_meta-{meta_key} -- for simple fields & writing lists as array to single meta record
* post_meta-{meta_key}-.3 -- for multi-input fields
* post_meta-{repeater_key}-1.{meta_key} -- for list fields mapped to meta readable by ACF
*/
// Run this function after the Gravity Form has created a post
@freezvd
freezvd / edm-display-product-thumbnail-in-emails.php
Created August 4, 2018 09:46 — forked from edmundcwm/edm-display-product-thumbnail-in-emails.php
Woocommerce: Display order item thumbnails in transaction emails
<?php
/*
* Enable order item thumbnail display in emails
* Change order item thumbnail size
* @see woocommerce/includes/wc-template-functions.php for hook
*/
function edm_display_product_thumbnail_in_emails( $args ) {
/* Display image thumbnail in emails */
$args['show_image'] = true;
/**
* @description Minimum, maximum, incremental and start quantity for products | WooCommerce
* @author Fabio Tielen / Code Agency / https://codeagency.be
* @testedwith WooCommerce 3.3
*/
add_filter( 'woocommerce_quantity_input_args', 'ca_woocommerce_quantity_increment_changes', 10, 2 );
function ca_woocommerce_quantity_increment_changes( $args, $product ) {
if ( is_singular( 'product' ) ) {
@freezvd
freezvd / WooCommerce: Deny customer checkout if pending order
Created July 11, 2018 07:28
WooCommerce: Deny customer checkout if pending order
add_action('woocommerce_before_checkout_form', 'loc_deny_checkout_user_pending_orders');
function loc_deny_checkout_user_pending_orders( $posted ) {
global $woocommerce;
$customer = wp_get_current_user();
if (!empty($customer)) {
$customer_orders = get_posts(
array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $customer->ID,
@freezvd
freezvd / gist:f6bb872d095ec907cc0b14187cd5cadc
Created July 9, 2018 12:46 — forked from codeagencybe/gist:a1542fbc5b25cbb295be910afbf15f73
automatically add product to cart when cart total is above certain amount
/**
* @snippet Automatically add a specific product to cart when cart amount is above certain amount
* @author Fabio Tielen // Code Agency // https://codeagency.be
* @testedwith Woo 3.3+
*/
add_action( 'template_redirect', 'codeagency_add_product_to_cart' );
function codeagency_add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;