Skip to content

Instantly share code, notes, and snippets.

View klihelp's full-sized avatar
🎯
Focusing on life and money farm

klihelp

🎯
Focusing on life and money farm
View GitHub Profile
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 50;
if ( WC()->cart->total < $minimum ) {
if( is_cart() ) {
/**
* Allows to duplicate products with the capability edit_products
*/
add_filter( 'woocommerce_duplicate_product_capability', create_function( '', 'return "edit_products";' ) );
@woogist
woogist / functions.php
Created March 3, 2015 07:31
Hides checkout fields based on the products in the cart
/**
* Hides checkout fields based on the products in the cart
*
* @param array $fields
* @return array
*/
function conditional_checkout_fields_products( $fields ) {
$cart = WC()->cart->get_cart();
foreach ( $cart as $item_key => $values ) {
/**
* Does not filter related products by tag
*/
add_filter( 'woocommerce_product_related_posts_relate_by_tag', '__return_false' );
/**
* Does not filter related products by category
*/
add_filter( 'woocommerce_product_related_posts_relate_by_category', '__return_false' );
@phpdave
phpdave / cspheader.php
Last active November 24, 2024 14:05
CSP Header for PHP or Apache or .htaccess - Content Security Protocol
<?
//CSP only works in modern browsers Chrome 25+, Firefox 23+, Safari 7+
$headerCSP = "Content-Security-Policy:".
"connect-src 'self' ;". // XMLHttpRequest (AJAX request), WebSocket or EventSource.
"default-src 'self';". // Default policy for loading html elements
"frame-ancestors 'self' ;". //allow parent framing - this one blocks click jacking and ui redress
"frame-src 'none';". // vaid sources for frames
"media-src 'self' *.example.com;". // vaid sources for media (audio and video html tags src)
"object-src 'none'; ". // valid object embed and applet tags src
"report-uri https://example.com/violationReportForCSP.php;". //A URL that will get raw json data in post that lets you know what was violated and blocked
@JoostKiens
JoostKiens / convertImageToGrayscale.js
Created February 19, 2015 12:50
Convert an image to grayscale using canvas, takes around 25 ms for an image of 500px x 400px
define(function () {
'use strict';
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
return function ($srcImg) {
var deferred = $.Deferred();
var srcImg = $srcImg[0];
@Turbo87
Turbo87 / app.js
Created February 15, 2015 04:05
webpack + font-awesome test
require('font-awesome/css/font-awesome.css');
document.body.innerHTML = '<i class="fa fa-fw fa-question"></i>';
add_action( 'wc_custom_thankyou_failed', 'wc_custom_thankyou_failed', 10 );
function wc_custom_thankyou_failed( $order ) {
wc_get_template( 'custom-thankyou/failed.php', array( 'order' => $order ) );
}
add_action( 'wc_custom_thankyou_successful', 'wc_custom_thankyou_header', 10 );
function wc_custom_thankyou_header( $order ) {
wc_get_template( 'custom-thankyou/header.php', array( 'order' => $order ) );
}
@wpmark
wpmark / wp_terms_query.php
Created January 21, 2015 17:03
Query Posts from Different Terms
<?php
/* get the terms for the taxonomy */
$terms = get_terms(
'taxonomy_name_here',
array(
'hide_empty' => false
)
);
@woogist
woogist / customer-details.php
Created January 21, 2015 15:40
Show the customer details in the thank you page
<header>
<h2><?php _e( 'Customer details', 'woocommerce' ); ?></h2>
</header>
<dl class="customer_details">
<?php
if ( $order->billing_email ) echo '<dt>' . __( 'Email:', 'woocommerce' ) . '</dt><dd>' . $order->billing_email . '</dd>';
if ( $order->billing_phone ) echo '<dt>' . __( 'Telephone:', 'woocommerce' ) . '</dt><dd>' . $order->billing_phone . '</dd>';
// Additional customer details hook
do_action( 'woocommerce_order_details_after_customer_details', $order );