Skip to content

Instantly share code, notes, and snippets.

@gmmedia
gmmedia / functions.php
Last active January 17, 2024 13:56
Enable Gutenberg editor for WooCommerce
<?php
// Find the description at https://bloggerpilot.com/en/gutenberg-for-woocommerce/
// Disable new WooCommerce product template (from Version 7.7.0)
function bp_reset_product_template($post_type_args) {
if (array_key_exists('template', $post_type_args)) {
unset($post_type_args['template']);
}
return $post_type_args;
}
@iqbalrony
iqbalrony / custom-css.php
Last active November 22, 2023 11:56
How to add custom css control with elementor free version.
<?php
use Elementor\Controls_Manager;
use Elementor\Element_Base;
use Elementor\Core\Files\CSS\Post;
use Elementor\Core\DynamicTags\Dynamic_CSS;
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
@FermiDirak
FermiDirak / NYTPaywallWorkaround.md
Created May 19, 2019 03:44
Steps to get around NYT Paywall

A step by step guide wallthrough on how to access / read a NYT paywalled article

  1. Open the NYT article you want to read in incognito mode
  2. Open up your devtool console ([cmd][shift][j] on chrome/mac)
  3. Open up the devtools command prompt ([cmd][shift][P] on chrome/mac)
  4. Type in the command disable javascript into the command prompt, but don't hit enter
  5. Reload the page
  6. After the content loads but before the paywall appears, enter your disable javascript command
  7. If paywall persists, return to step 3. Otherwise, enjoy your free article.
  8. Happy reading!
@patilvikasj
patilvikasj / wcf_prepopulate_email.php
Last active October 10, 2019 19:41
Prepopulate Woo-commerce billing email field from GET parameter
/**
* Pre-populate Woocommerce checkout fields
*/
add_filter( 'woocommerce_checkout_get_value', 'prepopulate_email_field', 10, 2 );
function prepopulate_email_field( $input, $key ) {
switch ( $key ) {
case "billing_email":
@WillBrubaker
WillBrubaker / file.php
Created December 12, 2018 11:35
WooCommerce redirect to cart if trying to add a 'sold individually' item that is already in the cart
//not sure what to do with this code snippet? See https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/
add_filter( 'woocommerce_add_to_cart_sold_individually_found_in_cart', 'handsome_bearded_guy_maybe_redirect_to_cart' );
function handsome_bearded_guy_maybe_redirect_to_cart( $found_in_cart ) {
if ( $found_in_cart ) {
wp_safe_redirect( wc_get_page_permalink( 'cart' ) );
exit;
}
@patilvikasj
patilvikasj / enable_default_coupon.php
Last active October 10, 2019 19:40
Enabled default Woo-commerce coupon field on CartFlows checkout page
// Supposed to add this code in theme's functions.php.
add_action( 'wp', 'enabled_default_coupon_form' );
/**
* Action to add filter for enabling default WooCommerce coupon field.
*/
function enabled_default_coupon_form() {
// Bail if CartFlows is not active.
<?php
/**
* Prevent products being purchased from archive
* @return Boolean
*/
function pewc_filter_is_purchasable( $is_purchasable, $product ) {
if( is_archive() ) {
return false;
}
return $is_purchasable;
@corsonr
corsonr / functions.php
Created July 13, 2018 09:06
WooCommerce: Add conditional checkout fields based on products in cart
<?php // Do not include this if already open! Code goes in theme functions.php.
/**
* Add fields to the checkout page based on products in cart.
*
* @how-to https://remicorson.com/?p=7871
* @author Remi Corson
* @testedwith WooCommerce 3.4.0
*/
@verygoodplugins
verygoodplugins / wpf-tags-as-body-classes.php
Last active December 14, 2023 13:22
Add tags as classes to the body
<?php
// Adds a current logged in users tags to the <body> element's classes.
function wpf_tags_body_class( $classes ) {
if ( ! function_exists( 'wp_fusion' ) ) {
return $classes;
}
@RadGH
RadGH / rs_upload_from_url.php
Last active October 1, 2024 08:07
Upload a file from a URL to the WordPress media gallery. Supports images, PDFs, and other file types.
<?php
/**
* This function uploads a file from a URL to the media library, designed to be placed in your own theme or plugin.
* Metadata will be generated and images will generate thumbnails automatically.
*
* HOW TO USE:
* 1. Add the function below to your theme or plugin
* 2. Call the function and provide the URL to an image or other file.
* 3. If successful, the attachment ID will be returned.