Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / divi-icon-glyphs.js
Created April 6, 2019 00:28
Create glyphs of each icon from divi icon codes from dividezigns.com
// Run this code at https://dividezigns.com/divi-icon-codes/
// Glyphs will be added beneath every icon code
jQuery('.et_pb_section_1 .et_pb_row_2 .et_pb_text_inner ul li[class] em').each(function() {
var entity = '&#x' + jQuery(this).text().trim().replace('\\', '') + ';';
var glyph = jQuery('<div>').html( entity );
jQuery(this).append( glyph );
});
@RadGH
RadGH / divi-icon-font.css
Last active April 6, 2019 00:29
Divi Icon Font with CSS
/* Custom divi icons via <span class="rs-divi-icon" data-icon="l"></span> where the data-icon "l" refers to hex character "\6c" */
/* To locate icons, refer to https://dividezigns.com/divi-icon-codes/ */
/* Run this JS on that page to generate a glyph for every icon which you can easily copy: https://gist.github.com/RadGH/6c12de50f590d0aaee7974e2d79c914b */
/* Or, convert the hex number to glyph in html using &#x04D2; and copy the glyph manually (in php, use html_entity_decode on it) */
.rs-divi-icon:before {
font-family: "ETmodules" !important;
text-shadow: 0 0;
font-weight: normal;
font-style: normal;
font-variant: normal;
@RadGH
RadGH / var-dump-cart-item-key-and-data.txt
Created April 5, 2019 03:36
Get cart items, var_dump cart item key and data
foreach( WC()->cart->get_cart_contents() as $cart_item_key => $cart_item ) {
var_dump($cart_item_key);
var_dump($cart_item);
}
----
$cart_item_key
string(32) "21e6ce98c8943660f4ccf0435058083d"
@RadGH
RadGH / wc-conditional-emails.php
Created April 4, 2019 08:41
WooCommerce: How to conditionally enable specific email notifications based on products in the cart
<?php
/**
* When a completed order email is triggered, the email is normally disabled in the settings.
*
* For the PDF workbook, we want to enable it regardless. This is because it is virtual, and does not reach the "processing" step.
*
* @param $enabled
* @param $order
@RadGH
RadGH / wc-resend-email.php
Created April 4, 2019 08:31
How to manually re-send a woocommerce order notification
<?php
// This one is VERY COMPLICATED!! It will re-send the "completed" order email based on order id.
add_action( 'init', function() {
do_action( 'woocommerce_order_status_completed_notification', 40057 );
});
@RadGH
RadGH / acf-sort-repeater-by-date.js
Last active March 21, 2019 02:29
ACF: Sort a repeater by date input as one of the fields
// See: https://radleysustaire.com/s3/2558db/chrome.
// Works with any date format Javascript supports.
// Includes support for "1st" "2nd" "3rd" dates, as well.
// Change field id 5c92eba251e6b to your repeater field key, without the field_ prefix.
// Change field id 5c92ef539f442 to your date field key, without the field_ prefix.
// Not designed for nested repeaters but you could make it work by navigating through specific children.
// Recommend caching selectors with a variable.
jQuery('.acf-field.acf-field-5c92eba251e6b').find('.acf-repeater tbody').first().prepend(function() {
return jQuery(this).children('tr.acf-row').not('.acf-clone').sort(function(a,b) {
@RadGH
RadGH / simple-desktop-mobile-responsive-image-sizes.php
Last active May 7, 2019 04:39
Simple desktop/mobile responsive image sizes
<?php
$full_url = $hero['image']['url'];
$mobile_url = $hero['image_mobile']['url'];
$alt = $hero['image']['alt'];
$breakpoint = 480; // Mobile image will display at or below this breakpoint.
printf(
'<picture>
<source media="(max-width: %dpx)" srcset="%s">
<source media="(min-width: %dpx)" srcset="%s">
@RadGH
RadGH / wc-validate-product-is-purchasable.php
Last active May 26, 2019 11:09
WooCommerce: Validate if a product is purchasable with php
<?php
/**
* Only allow purchasing this product if a certain condition is met.
*
* @param WC_Cart $cart
*/
function rs_verify_if_user_can_purchase_product( WC_Cart $cart ) {
if ( !$cart instanceof WC_Cart ) return;
if ( $cart->is_empty() ) return;
@RadGH
RadGH / wc-cart-item-var_dump.php
Last active August 6, 2021 19:37
WooCommerce: $cart_item var_dump
<?php
foreach( WC()->cart->get_cart_contents() as $cart_item_key => $cart_item ) {
var_dump($cart_item);
exit;
}
?>
array(13) {
["key"]=>
string(32) "c3804daac5b8859f0975d20c9fe3370e"
@RadGH
RadGH / wc-display-products-column-on-orders.php
Created February 22, 2019 07:46
WooCommerce: Display products purchased as column in orders screen
<?php
/**
* Add a column to the orders screen that lists products that were purchased
*/
function aa_product_order( $columns ) {
$columns['product-display'] = __( 'Products' );
return $columns;
}