Skip to content

Instantly share code, notes, and snippets.

@runezero
runezero / get_search_form.php
Last active May 25, 2022 13:27
[Shop search redirect] Redirect the search bar to the shop page for product search #woocommerce
add_filter('get_search_form', 'adjust_search_form');
function adjust_search_form($html){
$home = get_home_url();
$shop = wc_get_page_permalink( 'shop' );
if($home == $shop){
$shop = $home .'/shop';
}
$html = str_replace($home, $shop, $html);
return $html;
@runezero
runezero / woocommerce_default_catalog_orderby.php
Created May 25, 2022 13:25
[Force shop sorting] Set the WooCommerce sorting to a parameter if a parameter is set #woocommerce
add_filter('woocommerce_default_catalog_orderby', 'default_catalog_orderby');
function default_catalog_orderby( $sort_by ) {
if(count($_GET) < 1 || isset($_GET['s']) && count($_GET) == 1){
return 'date';
}
return $sort_by;
}
@runezero
runezero / woocommerce_variable_price_html.php
Created May 25, 2022 13:29
[Set variable price range to from] Switch the variable product price range from the price range to a price from #woocommerce
add_filter( 'woocommerce_variable_sale_price_html', 'woodev_variable_price_range', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'woodev_variable_price_range', 10, 2 );
function dev_variable_price_range( $dev_price, $product ) {
$prefix = sprintf('%s: ', __('Vanaf', 'translate_domain'));
$dev_reg_min_price = $product->get_variation_regular_price( 'min', true );
$dev_min_sale_price = $product->get_variation_sale_price( 'min', true );
$dev_max_price = $product->get_variation_price( 'max', true );
$dev_min_price = $product->get_variation_price( 'min', true );
@runezero
runezero / delete_products.sql
Created May 25, 2022 13:31
[Delete products] SQL query to delete all products #woocommerce
DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product');
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
DELETE FROM wp_posts WHERE post_type = 'product';
@runezero
runezero / delete_woo_orders.php
Created May 25, 2022 13:32
[Delete orders] Delete WooCommerce orders older than 6 months executable #woocommerce
add_action('admin_init', function(){
$args = array(
'date_created' => '<' . ( time() - (3600*24*31*6) ),
'limit' => 1000
);
$orders = wc_get_orders( $args );
foreach ($orders AS $order) {
wp_delete_post($order->get_id(), true);
}
@runezero
runezero / gform_html_message_template_pre_send_email.php
Created May 25, 2022 13:34
[Gravity mails with Woo Styling] Set the header, footer and body styling within Gravity Mails to WooCommerce Mails #woocommerce #gravityforms
add_filter( 'gform_html_message_template_pre_send_email', 'maybe_enable_wc_template_for_gf_notifications');
function maybe_enable_wc_template_for_gf_notifications($template){
if(class_exists('woocommerce')) {
ob_start();
wc_get_template( 'emails/email-header.php', array( 'email_heading' => '{subject}' ) );
echo '<style>';
wc_get_template( 'emails/email-styles.php');
echo '</style>';
@runezero
runezero / woocommerce_before_cart_contents.php
Last active May 25, 2022 20:06
[Checkout notice free shipping at cart price] Set Woo Checkout notice to inform about free shipping from specific price in cart #woocommerce
<?php
add_action('woocommerce_before_cart_contents', 'woo_notice_free_shipping_minimal_price');
function woo_notice_free_shipping_minimal_price() {
global $woocommerce;
$bedragGratisVerzenden = 75;
$cart_total = floatval($woocommerce->cart->cart_contents_total);
$extraForFreeShipping = $bedragGratisVerzenden - $cart_total;
@runezero
runezero / woocommerce_register_post_type_product.php
Created May 25, 2022 13:39
[Enable product revisions] Enable WooCommerce product revisions on products, only enable on shops with small amount of products #woocommerce
add_filter( 'woocommerce_register_post_type_product', 'wc_modify_product_post_type' );
function wc_modify_product_post_type( $args ) {
$args['supports'][] = 'revisions';
return $args;
}
@runezero
runezero / avf_post_css_create_file.php
Last active May 25, 2022 13:52
[Disable css create file] Disables the function that lets Enfold create custom CSS files for pages #enfold
add_filter('avf_post_css_create_file', '__return_false');
@runezero
runezero / avf_logo.php
Last active May 25, 2022 13:51
[Change mobile logo] Change the mobile logo in the header on page load #enfold
add_filter('avf_logo','av_change_logo');
function av_change_logo($logo) {
if(wp_is_mobile()) {
$logo = "https://url-to-logo.com/path";
}
return $logo;
}