Skip to content

Instantly share code, notes, and snippets.

@Sanabria
Sanabria / woo_cart_has_virtual_product.php
Created September 16, 2023 03:02 — forked from smeric/woo_cart_has_virtual_product.php
Check if the WooCommerce cart contains virtual product
<?php
/**
* Check if the cart contains virtual product
*
* @return bool
*/
function woo_cart_has_virtual_product(){
global $woocommerce;
// By default, no virtual product
@Sanabria
Sanabria / Wordpress: Do if the_content is not empty
Created September 15, 2023 03:36 — forked from bhongy/Wordpress: Do if the_content is not empty
Wordpress: Check if the_content is empty / do something only when the_content is empty
<?php if ( get_the_content() ) { ?>
// do or output something
<?php } ?> // break php tag for HTML block
@Sanabria
Sanabria / front-page.php
Created September 13, 2023 18:08 — forked from lmartins/front-page.php
WooCommerce custom loop for Featured Products
<?php
$args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes',
'posts_per_page' => 6
);
$featured_query = new WP_Query( $args );
if ($featured_query->have_posts()) :
?>
/**
* Sage required files
*
* The mapped array determines the code library included in your theme.
* Add or remove files to the array as needed. Supports child theme overrides.
*/
array_map(function ($file) use ($sage_error) {
$file = "../app/{$file}.php";
if (!locate_template($file, true, true)) {
$sage_error(sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file), 'File not found');
@Sanabria
Sanabria / functions.php
Created March 4, 2022 03:29 — forked from claudiosanches/functions.php
Wordpress Related Posts function
<?php
/**
* Related Posts.
*
* Usage:
* To show related by categories:
* Add in single.php <?php dfw_related_posts(); ?>.
* To show related by tags:
* Add in single.php <?php dfw_related_posts('tag'); ?>.
@Sanabria
Sanabria / debug-scroll.md
Created January 19, 2022 05:05 — forked from cuth/debug-scroll.md
Find the elements that are causing a horizontal scroll. Based on http://css-tricks.com/findingfixing-unintended-body-overflow/

Debug Horizontal Scroll

(function (d) {
    var w = d.documentElement.offsetWidth,
        t = d.createTreeWalker(d.body, NodeFilter.SHOW_ELEMENT),
        b;
    while (t.nextNode()) {
        b = t.currentNode.getBoundingClientRect();
 if (b.right &gt; w || b.left &lt; 0) {
@Sanabria
Sanabria / editor-add-roles.php
Created November 9, 2021 22:25 — forked from chrisguitarguy/editor-add-roles.php
Allow users with the role editor to add users to WordPress -- but only subscribers.
<?php
/*
Plugin Name: Editors Add Users
Description: Allow editors to add user roles
Author: Christopher Davis
Author URI: http://www.christopherguitar.me
License: GPL2
*/
register_activation_hook( __FILE__, 'wpse42003_activation' );
@Sanabria
Sanabria / functions.php
Created November 3, 2021 21:20 — forked from ronipl/functions.php
Woocommerce custom date picker field on checkout page
<?php
/**
* Add the custom field on checkout page
*/
add_action( 'woocommerce_after_checkout_billing_form', 'display_extra_fields_after_billing_address' , 10, 1 );
function display_extra_fields_after_billing_address () {
_e( "Delivery Date: ", "add_extra_fields");
?>
@Sanabria
Sanabria / functions.php
Created October 27, 2021 04:47 — forked from pacmanito/functions.php
WooCommerce - Add send customer order notes email option
<?php
/**
* This adds an option to send order notes email manually via order actions drop-down.
*/
/**
* Filter to add a new menu to the dropdown
*
* @param array $actions
* @return array