Skip to content

Instantly share code, notes, and snippets.

View netwizards's full-sized avatar

Krzysztof netwizards

View GitHub Profile
@netwizards
netwizards / functions.php
Created July 31, 2024 08:47 — forked from certainlyakey/functions.php
Remove an item from Breadcrumbs NavXT plugin trail (Wordpress)
if (function_exists('bcn_display')) {
function theme_remove_news_from_trail_on_404($trail) {
if ( is_404() ) {
unset($trail->trail[1]);
array_keys($trail->trail);
}
}
add_action('bcn_after_fill', 'theme_remove_news_from_trail_on_404');
}
@netwizards
netwizards / functions.php
Created February 28, 2024 21:41 — forked from paaljoachim/functions.php
WooCommerce show/hide products based on if the user is logged inn or logged out.
<?php
// https://businessbloomer.com/woocommerce-remove-specific-category-shop-loop/
// https://stackoverflow.com/questions/34684881/hide-products-from-users-who-are-not-logged-in-using-tags/34689768#34689768
add_action( 'woocommerce_product_query', 'show_hide_products_category_shop' );
function show_hide_products_category_shop( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
if ( is_user_logged_in() ) {
@netwizards
netwizards / gist:e8873478d721e0d70883919a490924a7
Created February 18, 2024 20:11 — forked from corsonr/gist:81a67e71dca0e9bd18f3
WooCommerce: filter shipping packages
add_filter( 'woocommerce_cart_shipping_packages', 'bulky_woocommerce_cart_shipping_packages' );
function bulky_woocommerce_cart_shipping_packages( $packages ) {
// Reset the packages
$packages = array();
// Bulky items
$bulky_items = array();
$regular_items = array();
@netwizards
netwizards / woocommerce_update_shipping_costs.php
Created February 18, 2024 20:10 — forked from neamtua/woocommerce_update_shipping_costs.php
WooCommerce: Update shipping costs on checkout using ajax
<script type="text/javascript">
/* in order to update info on your checkout page you need to trigger update_checkout function
so add this in your javascript file for your theme or plugin
*/
jQuery('body').trigger('update_checkout');
/* what this does is update the order review table but what it doesn't do is update shipping costs;
the calculate_shipping function of your shipping class will not be called again;
so if you were like me and you made a shipping method plugin and you had to change costs based on payment method then
@netwizards
netwizards / functions.php
Created February 16, 2024 18:50
Replace add to cart button by a linked button to the product in Shop and archives pages
// Replace add to cart button by a linked button to the product in Shop and archives pages
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
function replace_loop_add_to_cart_button( $button, $product ) {
// Not needed for variable products
if( $product->is_type( 'variable' ) ) return $button;
// Button text here
$button_text = __( "View product", "woocommerce" );
return '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
@netwizards
netwizards / functions.php
Last active February 16, 2024 18:33
Change Select Option Text in WooCommerce on Variable product
function woo_jazz_select_text_change() {
if ( $product->is_type( 'variable' ) ) {
return __( 'View product', 'woocommerce' );
}
return $label;
}
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_jazz_select_text_change', 9999, 2 );
@netwizards
netwizards / functions.php
Created February 16, 2024 18:29
Enable shortcodes for menu navigation
/**
* Enable shortcodes for menu navigation.
*/
if ( ! has_filter( 'wp_nav_menu', 'do_shortcode' ) ) {
add_filter( 'wp_nav_menu', 'shortcode_unautop' );
add_filter( 'wp_nav_menu', 'do_shortcode', 11 );
}
@netwizards
netwizards / template-functions.php
Created May 30, 2023 08:40 — forked from interplaydesign/template-functions.php
wp_nav_menu_objects filter
/**
* Menu customizations
*/
add_filter('wp_nav_menu_objects', 'intro_nav_menu_objects', 10, 2);
function intro_nav_menu_objects( $items, $args ) {
//If our menu has the id primary-menu in the wp_nav_menu in our header.php
if ( $args->menu_id == 'primary-menu' ){
//var_dump( $items );
//For each item in the menu. the $item->ID is the menu item ID not the page/post ID
//The post id will be the $item->object_id if it is a post/page
@netwizards
netwizards / gist:54f034d87414d4fa852fdba2eba23099
Created April 12, 2023 18:43 — forked from bohnna/gist:0edf12dd39cf8883234f
(Wordpress) Remove UL from wp_nav_menu
<?php
$my_menu = array(
'menu' => 'main-menu',
'container' => '',
'items_wrap' => '%3$s'
);
wp_nav_menu( $my_menu );
<?php
// Get total number of orders in Woocommerce
$order_totals = apply_filters( 'woocommerce_reports_sales_overview_order_totals', $wpdb->get_row( "
SELECT COUNT(posts.ID) AS total_orders FROM {$wpdb->posts} AS posts
LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )