Skip to content

Instantly share code, notes, and snippets.

@momofone
momofone / functions.php
Created April 4, 2019 08:14 — forked from Arian-c27/functions.php
Keep expired listings accessible via direct link
add_action( 'init', function() {
global $wp_post_statuses;
if ( ! is_array( $wp_post_statuses ) ) {
$wp_post_statuses = [];
}
// @todo: make 'public' status optional, so expired listings can also be accessed from url (optionally).
if ( ! empty( $wp_post_statuses['expired'] ) ) {
$wp_post_statuses['expired']->public = true;
<?php
$images = get_post_meta( get_the_ID(), 'images', true );
if ( $images ) {
for( $i = 0; $i < $images; $i++ ) {
$image_name = get_post_meta( get_the_ID(), 'images_' . $i . '_image_name', true );
$image_path = get_post_meta( get_the_ID(), 'images_' . $i . '_image_path', true );
@momofone
momofone / gw-gravity-forms-map-fields-to-field.php
Created September 14, 2018 08:12 — forked from spivurno/gw-gravity-forms-map-fields-to-field.php
Gravity Wiz // Gravity Forms // Map Submitted Field Values to Another Field
<?php
/**
* Gravity Wiz // Gravity Forms // Map Submitted Field Values to Another Field
*
* Preview your Gravity forms on the frontend of your website. Adds a "Live Preview" link to the Gravity Forms toolbar.
*
* Usage
*
* 1 - Enable "Allow field to be populated dynamically" option on field which should be populated.
* 2 - In the "Parameter Name" input, enter the merge tag (or merge tags) of the field whose value whould be populated into this field.
@momofone
momofone / custom-events-wp_query.php
Created August 16, 2018 13:14 — forked from jo-snips/custom-events-wp_query.php
The Events Calendar - Custom Query Using WP_Query
<?php
$args = array(
'post_status'=>'publish',
'post_type'=>array(TribeEvents::POSTTYPE),
'posts_per_page'=>10,
//order by startdate from newest to oldest
'meta_key'=>'_EventStartDate',
'orderby'=>'_EventStartDate',
'order'=>'DESC',
@momofone
momofone / default_to_list.php
Created August 6, 2018 21:11 — forked from jo-snips/default_to_list.php
The Events Calendar - Default to List View on Event Categories
<?php
/*-------------------------------------------------------*/
/* Default to List View When Viewing Event Categories
/*-------------------------------------------------------*/
add_action( 'pre_get_posts', 'default_to_list_view' );
function default_to_list_view( $query ) {
if ( is_tax(TribeEvents::TAXONOMY) && $query->query_vars['post_type'] == TribeEvents::POSTTYPE && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'eventDisplay', 'upcoming' );
@momofone
momofone / rewrite-wc-bookings-get-time-slots-html.php
Created June 18, 2018 13:26 — forked from jessepearson/rewrite-wc-bookings-get-time-slots-html.php
Make it so that all time slots in a time-based booking in WooCommerce Bookings shows how many spots remain, not just partially booked blocks.
<?php // do not copy this line
function rewrite_wc_bookings_get_time_slots_html( $block_html, $available_blocks, $blocks ) {
$block_html = '';
foreach ( $available_blocks as $block => $quantity ) {
if ( $quantity['available'] > 0 ) {
$block_html .= '<li class="block" data-block="' . esc_attr( date( 'Hi', $block ) ) . '"><a href="#" data-value="' . date( 'G:i', $block ) . '">' . date_i18n( get_option( 'time_format' ), $block ) . ' <small class="booking-spaces-left">(' . sprintf( _n( '%d left', '%d left', $quantity['available'], 'woocommerce-bookings' ), absint( $quantity['available'] ) ) . ')</small></a></li>';
}
@momofone
momofone / lets-confirm-some-cod-bookings.php
Created June 18, 2018 13:21 — forked from jessepearson/lets-confirm-some-cod-bookings.php
Place Bookings into a confirmed status if they have been paid for via COD - for WooCommerce Bookings
<?php // only copy this line if needed
// related blog post: https://jessepearson.net/2016/11/woocommerce-bookings-cod-payments/
/**
* Function that will put bookings into a Confirmed status if they were paid for via COD
*
* @param int/string $order_id The order id
* @return null
*/
function lets_confirm_some_cod_bookings( $order_id ) {
global $wpdb;
@momofone
momofone / um-custom-tabs.php
Created June 18, 2018 12:54 — forked from houseraevan/um-custom-tabs.php
Add additional custom tabs to the Ultimate Member account page
<?php
add_filter( 'um_account_page_default_tabs_hook', 'factmaven_um_tabs', 100 );
add_action( 'um_account_tab__tab1', 'factmaven_um_tab_hook_tab1' );
add_action( 'um_account_tab__tab2', 'factmaven_um_tab_hook_tab2' );
add_filter( 'um_account_content_hook_tab1', 'factmaven_account_content_hook_tab1' );
add_filter( 'um_account_content_hook_tab2', 'factmaven_account_content_hook_tab2' );
// ULTIMATE MEMBER
function factmaven_um_tabs( $tabs ) { // Add Tab #1 tab
@momofone
momofone / functions.php
Created March 31, 2018 11:52 — forked from circlecube/functions.php
WillyMelt API Tweaks
// add custom fields query to WP REST API v2
// https://1fix.io/blog/2015/07/20/query-vars-wp-api/
function my_allow_meta_query( $valid_vars ) {
$valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value' ) );
return $valid_vars;
}
add_filter( 'rest_query_vars', 'my_allow_meta_query' );
@momofone
momofone / wc-admin-custom-order-fields-wc-api.php
Created March 31, 2018 11:32 — forked from tamarazuk/wc-admin-custom-order-fields-wc-api.php
WooCommerce Admin Custom Order Fields - Allow custom order fields to be accessed by the WooCommerce REST API
<?php // only copy this line if needed
function sv_wc_api_allow_acof_protected_meta() {
add_filter( 'is_protected_meta', 'sv_wc_acof_is_protected_meta', 10, 2 );
}
add_action( 'woocommerce_api_loaded', 'sv_wc_api_allow_acof_protected_meta' );
function sv_wc_acof_is_protected_meta( $protected, $meta_key ) {
if ( 0 === strpos( $meta_key, '_wc_acof_' ) ) {