Skip to content

Instantly share code, notes, and snippets.

View webdados's full-sized avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / woocommerce_hide_default_category.php
Created February 8, 2018 10:38
Hide WooCommerce (3.3 and above) default category
<?php
/* Hide WooCommerce default category on the frontend */
add_filter( 'woocommerce_product_subcategories_args', 'woocommerce_hide_default_category' );
function woocommerce_hide_default_category( $args ) {
$args['exclude'] = get_option( 'default_product_cat' );
return $args;
}
@webdados
webdados / custom_nav_menu_item_title.php
Last active February 28, 2018 10:52
Change WooCommerce "My Account" item menu title when the user is logged in
<?php
/* If you want to limit it to a specific theme location */
add_filter( 'nav_menu_item_title', 'custom_nav_menu_item_title', 10, 3 );
function custom_nav_menu_item_title( $title, $item, $args ) {
//Menu item should be set with the text you want to use for "logged out" users
//Logged in?
if ( is_user_logged_in() ) {
//Correct menu location
$theme_locations = array( 'acc-menu', 'mobile-secondary-menu' ); //Update to your own locations here
if ( isset( $args->theme_location ) && in_array( $args->theme_location, $theme_locations ) ) {
@webdados
webdados / remove_wc_add_to_cart_message_html.php
Created March 1, 2018 17:22
Remove WooCommerce "Added to cart" message
<?php
/* Removes the "added to cart" message and "continue shopping" link after a product was added to the cart and the user was redirected to the cart page */
add_filter( 'wc_add_to_cart_message_html', 'remove_wc_add_to_cart_message_html' );
function remove_wc_add_to_cart_message_html( $message ) {
$message = '';
return $message;
}
?>
@webdados
webdados / pvkw_map_dimensions.php
Created March 5, 2018 10:16
Override "Portugal VASP Expresso Kios network for WooCommerce" map dimensions
<?php
add_filter( 'pvkw_map_width', function( $width ) {
return 200;
} );
add_filter( 'pvkw_map_height', function( $height ) {
return 100;
} );
@webdados
webdados / pvkw_get_shipping_methods.php
Created March 5, 2018 10:18
Add incompatible shipping methods to VASP Expresso Kios network for WooCommerce
<?php
add_filter( 'pvkw_get_shipping_methods', 'woocommerce_flatrate_percountry_pvkw_get_shipping_methods' );
function woocommerce_flatrate_percountry_pvkw_get_shipping_methods( $shipping_methods ) {
$shipping_methods[] = 'woocommerce_flatrate_percountry';
return $shipping_methods;
}
@webdados
webdados / wc-disable-city-postcode-shipping-calculator.php
Created March 6, 2018 17:43
Disable city / postcode on the WooCommerce cart shipping calculator
<?php
//Disable city field on the WooCommerce cart shipping calculator
add_filter( 'woocommerce_shipping_calculator_enable_city', '__return_false' );
//Disable postcode field on the WooCommerce cart shipping calculator
add_filter( 'woocommerce_shipping_calculator_enable_postcode', '__return_false' );
@webdados
webdados / div-update-ajax.php
Last active March 20, 2018 14:07
Shortcode and automatic AJAX content reload immediately after page load - WordPress
<?php
/* Shortcode actualizado por Ajax */
//My shortcode that outputs the DIV and the necessary javascript (which should be external actually)
add_shortcode( 'my_shortcode' , 'my_shortcode_function' );
function my_shortcode_function() {
ob_start();
echo my_shortcode_function_content();
?>
@webdados
webdados / fb_og_update_cache_url.php
Last active March 28, 2018 19:38
Facebook Open Graph, Google+ and Twitter Card Tags with Access Token
<?php
/*
If you want the "Facebook Open Graph, Google+ and Twitter Card Tags" WordPress plugin to be able
to clear/update the cache of your posts and pages, you'll need to create a facebook app and add
it's ID and secret to the URL.
1) Go to https://developers.facebook.com/apps/ and create a new app (or choose and existant one, any app will do)
2) Copy the App ID and App Secret from your app dashboard
3) Add this to your (child-)theme's functions.php file and replace MY_APP_ID and MY_APP_SECRET with your app details
@webdados
webdados / wc_round_tax_total.php
Last active April 17, 2018 18:59
Fix tax rounding problems in WooCommerce
WooCommerce stores tax subtotals rounded with the same number of decimals that are set for the store, which can cause problems when invoicing on external services
Example when using 2 decimals and tax 23%:
Total itens (without tax): 68.24
Itens tax (rounded with 2 decimals): 15.6952 = 15.70
Shipping (without tax): 4.73
Shipping tax (rounded with 2 decimals): 1.0879 = 1.09
Total taxes: 16.79
Total: 72.97 + 16.79 = 89.76
@webdados
webdados / wse_screen_new_header.php
Last active May 29, 2018 18:35
Add CSS or other content to the output of the Stock Exporter for WooCommerce plugin when "HTML table on new window" is chosen
<?php
add_action( 'wse_screen_new_header', 'wse_screen_new_header_css', 11 );
function wse_screen_new_header_css() {
?>
<style type="text/css">
#stock-export-table .column-value-image img {
max-width: 200px;
max-height: 200px;
}