Skip to content

Instantly share code, notes, and snippets.

View webdados's full-sized avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / disable_auth.php
Created September 15, 2023 11:30
Disable WordPress authentication entirely
<?php
add_filter( 'authenticate', function( $user, $username ) {
return new WP_Error( 'foo', 'This account is disabled' );
}, 10, 2 );
@webdados
webdados / kk_increase_prices.php
Created August 14, 2023 10:06
Increase all prices on the Kuanto Kusta WooCommerce feed
<?php
/* Pro plugin: https://ptwooplugins.com/product/feed-kuantokusta-for-woocommerce-pro/ */
add_filter( 'kuantokusta_product_node_default_regular_price', 'kk_increase_prices' );
add_filter( 'kuantokusta_product_node_variation_regular_price', 'kk_increase_prices' );
add_filter( 'kuantokusta_product_node_default_current_price', 'kk_increase_prices' );
add_filter( 'kuantokusta_product_node_variation_current_price', 'kk_increase_prices' );
function kk_increase_prices( $price ) {
return $price * 1.15;
@webdados
webdados / woocommerce_get_availability.php
Last active August 10, 2023 20:10
Change "available on backorder" WooCommerce text
<?php
add_filter( 'woocommerce_get_availability', 'my_woocommerce_get_availability' );
function my_woocommerce_get_availability( $availability ) {
if ( $availability['class'] == 'available-on-backorder' ) {
$availability['availability'] = 'Your text here';
}
return $availability;
}
@webdados
webdados / shop_as_client_allow_checkout.php
Last active July 17, 2023 09:36
Shop as Client - Allow other user roles to use the functionality (Shop managers and Administrators already have the ability to do so)
<?php
add_filter( 'shop_as_client_allow_checkout', function() {
$user = wp_get_current_user();
return in_array( 'whatver_role', (array) $user->roles );
} );
@webdados
webdados / lang.html
Created July 13, 2023 07:32
Testing language changes with screen readers
<!DOCTYPE html>
<html lang="pt-PT">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<p>Junta-te à comunidade lisboeta no maior evento presencial desde o confinamento. Assiste às palestras sobre Marketing, SEO, comércio electrónico, tecnologia, conteúdo e tudo o que está relacionado com o WordPress e a web, também com espaço para o bem-estar pessoal. Participa nos workshops, contribui para este projecto open source e faz networking com a TUA comunidade.</p>
<!-- Testing lang attribute on a outter html element - It works for all inner elements -->
@webdados
webdados / postcode-before-address.php
Created July 6, 2023 15:45
Postcode before other address fields for "Portuguese Postcodes for WooCommerce" full address autocomplete mode
<?php
/* You should adapt the priorities to your scenario */
add_filter( 'woocommerce_get_country_locale', function( $countries ) {
if ( is_checkout() ) {
if ( function_exists( '\Webdados\PortuguesePostcodesWooCommerce\PortuguesePostcodesWooCommerce' ) ) {
if ( get_option( 'portuguese_postcodes_woo_mode' ) == '' && get_option( 'portuguese_postcodes_woo_autocomplete_mode' ) == 'full_address' ) {
$countries['PT']['postcode']['priority'] = 45;
$countries['PT']['city']['priority'] = 46;
if ( ! ( function_exists( 'woocommerce_portugal_states' ) || class_exists( 'WC_Webdados_Distritos' ) ) ) {
// Without the Distritos plugin active
@webdados
webdados / disable_sequra_for_low_values.php
Last active May 26, 2023 10:27
Only allow SeQura payment for orders above a certain value
<?php
// First of all define the minimum value on a constant, for easy change - Ideally this would be loaded from an option on the settings
define( 'SEQURA_MIN_VALUE', 200 );
// Set the filters
add_filter( 'woocommerce_available_payment_gateways', 'disable_sequra_for_low_values' );
add_filter( 'woocommerce_sq_is_available_in_product_page', 'disable_sequra_for_low_values_product_page', 10, 2 );
// Hide it on the checkout
@webdados
webdados / add_quantcast_choice_headar.php
Created July 4, 2022 11:41
Add the new (June 2022) Quantcast Choice code to your WordPress website header
<?php
add_action( 'wp_head', array( $this, 'quantcast_choice_enable_action' ), function() {
?>
<!-- Quantcast Choice. Consent Manager Tag v2.0 (for TCF 2.0) -->
<script type="text/javascript" async=true>
(function() {
var host = window.location.hostname;
var element = document.createElement('script');
var firstScript = document.getElementsByTagName('script')[0];
var url = 'https://cmp.quantcast.com'
@webdados
webdados / ifthen_send_email_instructions.php
Created March 22, 2022 13:03
Remove IfthenPay payment instructions from some WooCommerce emails
<?php
add_filter( 'multibanco_ifthen_send_email_instructions', 'my_multibanco_ifthen_send_email_instructions', 10, 5 );
add_filter( 'mbway_ifthen_send_email_instructions', 'my_multibanco_ifthen_send_email_instructions', 10, 5 );
add_filter( 'creditcard_ifthen_send_email_instructions', 'my_multibanco_ifthen_send_email_instructions', 10, 5 );
add_filter( 'payshop_ifthen_send_email_instructions', 'my_multibanco_ifthen_send_email_instructions', 10, 5 );
function my_multibanco_ifthen_send_email_instructions( $send, $order, $sent_to_admin, $plain_text, $email ) {
$emails_to_remove = array(
'customer_completed_order',
@webdados
webdados / flatsome_live_search_relevanssi_search_ok.php
Last active January 5, 2022 19:24
Make Flatsome live search work with Relevanssi
<?php
add_filter( 'relevanssi_search_ok', 'flatsome_live_search_relevanssi_search_ok' );
function flatsome_live_search_relevanssi_search_ok( $search_ok ) {
if ( is_ajax() && isset( $_GET['action'] ) && trim( $_GET['action'] ) == 'flatsome_ajax_search_products' ) {
return true;
}
return $search_ok;
}