Skip to content

Instantly share code, notes, and snippets.

Marek MrkKr

  • Poland
Block or report user

Report or block MrkKr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@MrkKr
MrkKr / additional_active_item_classes.php
Created Apr 5, 2019
Add top level menu active menu class to child pages without adding submenu level in admin panel
View additional_active_item_classes.php
<?php
function additional_active_item_classes( $classes = array(), $menu_item = false ) {
// custom taxonomy
if ( $menu_item->title == 'Custom Tax Name Page' && is_tax('custom_tax') ) {
$classes[] = 'current-menu-item';
}
// custom post type single
if ( $menu_item->title == 'Custom Post Type Page' && is_singular('products') ) {
$classes[] = 'current-menu-item';
@MrkKr
MrkKr / display_comment_from_selected_post.php
Created Feb 8, 2019
Wordpress - display comments form selected post
View display_comment_from_selected_post.php
<?php
$args = array('cat' => 'home','post_type' => 'post'));
$post_obj = new WP_Query($args);
while($post_obj->have_posts() ) : $post_obj->the_post();
//display comments
$comments = get_comments(array(
'post_id' => $post->ID,
'number' => '2' ));
foreach($comments as $comment) {
//format comments
@MrkKr
MrkKr / update_wp_urls.sql
Created Feb 5, 2019
Wordpress - Update all old URLs in database with SQL
View update_wp_urls.sql
UPDATE wp_options SET option_value = replace(option_value, 'OLD URL', 'NEW URL') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'OLD URL', 'NEW URL');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'OLD URL','NEW URL');
UPDATE wp_usermeta SET meta_value = replace(meta_value, 'OLD URL','NEW URL');
UPDATE wp_links SET link_url = replace(link_url, 'OLD URL','NEW URL');
UPDATE wp_comments SET comment_content = replace(comment_content , 'OLD URL','NEW URL');
UPDATE wp_posts SET post_content = replace(post_content, 'OLD URL', 'NEW URL');
UPDATE wp_links SET link_image = replace(link_image, 'OLD URL','NEW URL');
UPDATE wp_posts SET guid = replace(guid, 'OLD URL','NEW URL');
@MrkKr
MrkKr / custom_user_meta_in_users_and_edit_this_ind_user_page.php
Created Sep 7, 2018
Add column with custom user meta in admin panel and edit this in edit profile page
View custom_user_meta_in_users_and_edit_this_ind_user_page.php
<?php
/* Add custom column */
function woo_add_user_nip_column( $columns ) { // e.g. NIP
$columns['billing_company_nip'] = __( 'NIP', 'theme' );
return $columns;
}
add_filter( 'manage_users_columns', 'woo_add_user_nip_column' );
@MrkKr
MrkKr / get_current_url_wp.php
Created May 8, 2018
Wordpress - get current url by PHP #php
View get_current_url_wp.php
<?php
/// without prefix
$current_url = "//" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
/// with prefix
global $wp;
$current_url = home_url( add_query_arg( array(), $wp->request ) );
@MrkKr
MrkKr / add_custom_items_wrap_menu_wp.php
Created Apr 26, 2018
Add custom items (wraps) to menu item Wordpress #php
View add_custom_items_wrap_menu_wp.php
<?php
function my_nav_wrap() {
// default value of 'items_wrap' is <ul id="%1$s" class="%2$s">%3$s</ul>'
ob_start();
the_widget( 'WC_Widget_Product_Search' ); //in this case I need WC widget
$widget = ob_get_clean();
// open the <ul>, set 'menu_class' and 'menu_id' values
$wrap = '<ul id="%1$s" class="%2$s">';
@MrkKr
MrkKr / woo_dropdown_product_tag_filter.php
Last active Apr 26, 2018 — forked from dustyf/gist:5862035
Woo Commerce Dropdown to filter product tag within an archive page.
View woo_dropdown_product_tag_filter.php
<?php
function displayLocationDropdown() {
$html = '';
$html .= '<form class="location-select" method="post">';
$html .= '<select id="location-selector" name="location" class="location">';
$tag = wp_tag_cloud( array(
'format' => 'array',
@MrkKr
MrkKr / hide_default_woo_cat_from_widget.php
Created Apr 25, 2018
Hide default woocommerce category from product category widget #php
View hide_default_woo_cat_from_widget.php
<?php
/* hide uncategorized product category */
add_filter( 'woocommerce_product_categories_widget_args', 'custom_woocommerce_product_subcategories_args' );
function custom_woocommerce_product_subcategories_args( $args ) {
$args['exclude'] = get_option( 'default_product_cat' );
return $args;
}
@MrkKr
MrkKr / add_custom_items_to_wp_menu.php
Created Apr 25, 2018
Add custom items to menu in Wordpress #php
View add_custom_items_to_wp_menu.php
<?php
/* add custom items to primary menu */
add_filter('wp_nav_menu_items','add_search_box_to_menu', 10, 2);
function add_search_box_to_menu( $items, $args ) {
if( $args->theme_location == 'primary' ) /* ID of menu */
return $items.'CUSTOM THINGS';
return $items;
}
@MrkKr
MrkKr / display_woo_cart_item_with_total_amount.php
Created Apr 25, 2018
Display Woocommerce cart item amount and total amount #php
View display_woo_cart_item_with_total_amount.php
<?php
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php).
// Used in conjunction with https://gist.github.com/woogists/9a16fd2d0c982e780a5de89c30cbbd25
// Compatible with WooCommerce 3.0+. Thanks to Alex for assisting with an update!
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<a class="cart-customlocation" href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
You can’t perform that action at this time.