Skip to content

Instantly share code, notes, and snippets.

View yanknudtskov's full-sized avatar

Yan Knudtskov yanknudtskov

View GitHub Profile
@yanknudtskov
yanknudtskov / functions.php
Created February 14, 2019 16:58
Using acf/load_value filter to sort a repeater subfield which has dates in it
<?php
/**
* Sort order for ACF Field: acf_production_tour_periods_excluded_dates
*/
add_filter('acf/load_value/name=acf_production_tour_periods_excluded_dates', 'acf_production_tour_periods_excluded_dates_load_value', 10, 3);
function acf_production_tour_periods_excluded_dates_load_value( $value, $post_id, $field ) {
// vars
$order = array();
@yanknudtskov
yanknudtskov / archive.php
Last active February 7, 2019 12:44 — forked from billerickson/archive.php
Removing advanced custom fields from the frontend
<?php
/**
* Category Subtitle
*
*/
function be_category_subtitle() {
// Make sure this is a category archive
if( ! is_category() )
@yanknudtskov
yanknudtskov / functions.php
Last active February 7, 2019 12:44 — forked from billerickson/functions.php
Removing advanced custom fields from the frontend
<?php
function be_call_to_action() {
$title = esc_html( get_option( 'options_be_cta_title' ) );
$button_text = esc_html( get_option( 'options_be_cta_button_text' ) );
$button_url = esc_url( get_option( 'options_be_cta_button_url' ) );
if( $title && $button_text && $button_url )
echo '<div class="call-to-action"><div class="wrap"><p>' . $title . '</p><p><a href="' . $button_url . '" class="button">' . $button_text . '</a></p></div></div>';
@yanknudtskov
yanknudtskov / template-landing.php
Last active February 9, 2019 23:38 — forked from billerickson/template-landing.php
Removing advanced custom fields from the frontend
<?php
/**
* Your Child Theme
*
* Template Name: Landing
*/
/**
* Flexible Content
*
@yanknudtskov
yanknudtskov / functions.php
Last active February 7, 2019 12:44 — forked from billerickson/functions.php
Removing advanced custom fields from the frontend
<?php
$videos = get_post_meta( get_the_ID(), 'be_attorney_video', true );
if( $videos ) {
for( $i = 0; $i < $videos; $i++ ) {
$title = esc_html( get_post_meta( get_the_ID(), 'be_attorney_video_' . $i . '_title', true ) );
$video = esc_url( get_post_meta( get_the_ID(), 'be_attorney_video_' . $i . '_video', true ) );
$thumbnail = (int) get_post_meta( get_the_ID(), 'be_attorney_video_' . $i . '_thumbnail', true );
// Thumbnail field returns image ID, so grab image. If none provided, use default image
@yanknudtskov
yanknudtskov / functions.php
Last active February 12, 2019 15:16
Dynamically modify which featured image to get for woocommerce product imagee
<?php
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'yanco_woocommerce_single_product_image_thumbnail_html', 10, 2 );
function yanco_woocommerce_single_product_image_thumbnail_html( $html, $post_thumbnail_id ) {
$product_id = get_the_ID();
$product_id_to_get_data_from = $product_id;
if( get_field( 'acf_get_data_from_product_enabled', $product_id ) === true ) {
$product_id_to_get_data_from = get_field( 'acf_get_data_from_product', $product_id );
@yanknudtskov
yanknudtskov / functions.php
Created January 29, 2019 14:06
Autocomplete WooCommerce Subscriptions Orders
<?php
/**
* Autocomplete subscription 'parent' and 'renewal' orders
*/
add_filter( 'woocommerce_payment_complete_order_status', 'yanco_wcs_return_completed', 10, 3);
/**
* Return "completed" as an order status.
*
@yanknudtskov
yanknudtskov / functions.php
Created January 29, 2019 14:06
Autocomplete WooCommerce Orders
<?php
/**
* Autocomplete 'simple' orders
*/
add_action( 'woocommerce_thankyou', 'yanco_woocommerce_auto_complete_order' );
/**
* Updates the status of a correctly processed order to 'Complete'
*
@yanknudtskov
yanknudtskov / functions.php
Created January 29, 2019 14:06
Autocomplete WooCommerce Suscriptions orders that contain virtual products
<?php
add_filter( 'woocommerce_order_item_needs_processing' , 'yanco_woocommerce_order_item_needs_processing', 10, 3 );
function yanco_woocommerce_order_item_needs_processing( $needs_processing, $product, $order_ID ) {
$product_type = $product->get_type();
if ( $product->is_virtual()
&& ( 'subscription' == $product_type || 'subscription_variation' == $product_type || 'variable-subscription' == $product_type ) ) {
return false;
}
@yanknudtskov
yanknudtskov / functions.php
Created January 29, 2019 14:04
Modify the WooCommerce Product Filter Widget for categories to show the ancestors and the children
<?php
/**
* Modify WooCommerce Product filter widget
*/
add_filter( 'woocommerce_product_categories_widget_args', 'yanco_woocommerce_product_categories_widget_args', 10, 1 );
function yanco_woocommerce_product_categories_widget_args( $list_args ) {
$include_ids = array();