Skip to content

Instantly share code, notes, and snippets.

View dexit's full-sized avatar
🎯
Focusing

Rihards Mantejs dexit

🎯
Focusing
View GitHub Profile
<?php
/**
* @credits https://jeroensormani.com/adding-a-custom-woocommerce-product-type/
*/
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
add_action('init' , 'wc_pm_load_product_type');
function wc_pm_load_product_type() {
<?php
$posts = maybeCache('remote_posts_data', 7200, function () {
return do_remote_get('https://jsonplaceholder.typicode.com/posts/');
});
foreach ($posts as $post) {
echo "<h2>{$post->title}</h2>";
}
@dexit
dexit / shortcode.php
Created April 11, 2024 09:11 — forked from igorbenic/shortcode.php
Conditional Enqueueing of scripts in WordPress
<?php
add_action('wp_enqueue_scripts', 'enqueue_if_shortcode');
function enqueue_if_shortcode(){
global $post;
if ( $post && has_shortcode( $post->post_content, 'your_shortcode_tag' ) {
// Enqueue
}
@dexit
dexit / functions.php
Created April 11, 2024 09:10 — forked from yanknudtskov/functions.php
Apparently SearchWP/Relevanss and Elementor doesn't play well together with Elementor, Searches and post grid. This is the outline of handling searching in post_meta.
<?php
// Modify the fields to search in
add_action( 'elementor/query/searched_query', function( $query ) {
$s = get_search_query();
if ( is_search() ) {
$query->set( 'post_type', 'leverandor' );
if( strlen($s) >= 3 ) {
@dexit
dexit / functions.php
Created April 11, 2024 09:09 — forked from yanknudtskov/functions.php
WooCommerce Add Custom Fields to Products
<?php
// For variations
add_action( 'woocommerce_variation_options_pricing', 'yanco_add_custom_field_to_variations', 10, 3 );
function yanco_add_custom_field_to_variations( $loop, $variation_data, $variation ) {
woocommerce_wp_text_input( array(
'id' => 'custom_field[' . $loop . ']',
'class' => 'short',
'label' => __( 'Custom Field', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, 'custom_field', true )
@dexit
dexit / functions.php
Created April 11, 2024 09:09 — forked from yanknudtskov/functions.php
Example on how to meta query ACF repeater fields
<?php
add_shortcode( 'user_company_link', 'yanco_user_company_link' );
function yanco_user_company_link() {
if( ! is_user_logged_in() ) {
return;
}
$html = '';
@dexit
dexit / functions.php
Created April 11, 2024 09:09 — forked from yanknudtskov/functions.php
Add query string if failed login with Elementor Pro Login Form
<?php
add_action( 'wp_login_failed', 'yanco_elementor_form_login_fail' );
function yanco_elementor_form_login_fail( $username ) {
// where did the post submission come from?
$referrer = $_SERVER['HTTP_REFERER'];
// if there's a valid referrer, and it's not the default log-in screen
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
@dexit
dexit / functions.php
Created April 11, 2024 09:09 — forked from yanknudtskov/functions.php
Add a WooCommerce Checkbox at Checkout to accept privacy policy.
<?php
/**
* Add privacy policy tick box at checkout
*/
add_action( 'woocommerce_review_order_before_submit', 'yanco_add_checkout_privacy_policy', 9 );
function yanco_add_checkout_privacy_policy() {
woocommerce_form_field( 'privacy_policy', array(
'type' => 'checkbox',
'class' => array('form-row privacy'),
@dexit
dexit / functions.php
Created April 11, 2024 09:07 — forked from yanknudtskov/functions.php
This file contains a bunch of helper functions that handle add caching to core WordPress functions.
<?php
/**
* This file contains a bunch of helper functions that handle add caching to core WordPress functions.
*/
/**
* Cached version of get_category_by_slug.
*
* @param string $slug Category slug
* @return object|null|bool Term Row from database. Will return null if $slug doesn't match a term. If taxonomy does not exist then false will be returned.
@dexit
dexit / acf.js
Created April 11, 2024 09:05 — forked from igorbenic/acf.js
ACF Repeater Fields - Filter by Price
(function($){
$(function(){
$(document.body).on( 'change', '#min_price, #max_price', function(){
var minPrice = parseFloat( $('#min_price').val() );
var maxPrice = parseFloat( $('#max_price').val() );
$('.item-list li').each(function(){
var price = parseFloat( $(this).attr('data-price') );