Skip to content

Instantly share code, notes, and snippets.

View webdados's full-sized avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / bpinet_clean_iban.js
Last active October 7, 2017 14:23
Clean whitespaces from IBAN when pasting it on BPINet
//Add as many IBAN / NIB field IDs as you want
var ibanFields = [
"LT_BPINet_wt1_block_wtMainContent_CS_ClienteCanais_wt42_block_WebPatterns_wt581_block_wtContent_LT_BPI_Patterns_wtDadosBeneficiarioNacional_block_wtForm_LT_BPI_Patterns_wtRowIBAN_block_wtRow_LT_BPI_Patterns_wtIBAN_block_wtInput_wtTxtIBAN",
"LT_BPINet_wt20_block_wtMainContent_CS_Transferencias_wt12_block_wt3_WebPatterns_wt820_block_wtContent_LT_BPI_Patterns_wtfmFomularioDadosTranferencia_block_wtForm_LT_BPI_Patterns_wttxtIBAN_block_wtRow_LT_BPI_Patterns_wt652_block_wtInput_wttxtIBAN2",
"LT_BPINet_wt60_block_wtMainContent_CS_Transferencias_wt68_block_WebPatterns_wt273_block_wtContent_LT_BPI_Patterns_wt999_block_wtForm_LT_BPI_Patterns_wt442_block_wtRow_LT_BPI_Patterns_wt55_block_wtInput_wttxtContaIBANDestinatario"
];
//Add the event listener
for (var i = 0, len = ibanFields.length; i < len; i++) {
if ( el=document.getElementById(ibanFields[i]) ) el.addEventListener('paste', cleanIban);
@webdados
webdados / bpinet_paste_ref.js
Created October 11, 2017 10:02
Paste Multibanco reference into BPINet
var pagServField1 = "LT_BPINet_wt43_block_wtMainContent_CS_CartoesDebito_wt7_block_WebPatterns_wt122_block_wtContent_LT_BPI_Patterns_wt292_block_wtForm_LT_BPI_Patterns_wt57_block_wtRow_LT_BPI_Patterns_wt691_block_wtInput_wttxtRef1";
var pagServField2 = "LT_BPINet_wt43_block_wtMainContent_CS_CartoesDebito_wt7_block_WebPatterns_wt122_block_wtContent_LT_BPI_Patterns_wt292_block_wtForm_LT_BPI_Patterns_wt57_block_wtRow_LT_BPI_Patterns_wt691_block_wtInput_wttxtRef2";
var pagServField3 = "LT_BPINet_wt43_block_wtMainContent_CS_CartoesDebito_wt7_block_WebPatterns_wt122_block_wtContent_LT_BPI_Patterns_wt292_block_wtForm_LT_BPI_Patterns_wt57_block_wtRow_LT_BPI_Patterns_wt691_block_wtInput_wttxtRef3";
if ( el=document.getElementById(pagServField1) ) el.addEventListener('paste', pasteRef);
function pasteRef(e) {
e.stopPropagation();
e.preventDefault();
var clipboardData = e.clipboardData || window.clipboardData;
@webdados
webdados / cppw_get_shipping_methods.php
Created November 3, 2017 17:15
Add incompatible shipping methods to Portugal Chronopost Pickup network for WooCommerce
<?php
add_filter( 'cppw_get_shipping_methods', 'woocommerce_flatrate_percountry_cppw_get_shipping_methods' );
function woocommerce_flatrate_percountry_cppw_get_shipping_methods( $shipping_methods ) {
$shipping_methods[] = 'woocommerce_flatrate_percountry';
return $shipping_methods;
}
@webdados
webdados / woocommerce_register_form_start_client_type.php
Created November 21, 2017 08:13
Add custom field "client type" to WooCommerce registration
/* Add client type field to registration */
add_action( 'woocommerce_register_form_start', 'woocommerce_register_form_start_client_type' );
function woocommerce_register_form_start_client_type() {
?>
<p class="form-row form-row-wide">
<label for="reg_client_type"><?php _e( 'Client type', 'textdomain' ); ?></label>
<select class="" name="client_type" id="client_type">
<option value="person"<?php if ( isset($_POST['client_type']) && $_POST['client_type']=='person' ) echo ' selected="selected"'; ?>><?php _e( 'Person', 'textdomain' ); ?></option>
<option value="company"<?php if ( isset($_POST['client_type']) && $_POST['client_type']=='company' ) echo ' selected="selected"'; ?>><?php _e( 'Company', 'textdomain' ); ?></option>
</select>
@webdados
webdados / cppw_map_dimensions.php
Created November 23, 2017 14:59
Override "Portugal Chronopost Pickup network for WooCommerce" map dimensions
<?php
add_filter( 'cppw_map_width', function( $width ) {
return 200;
} );
add_filter( 'cppw_map_height', function( $height ) {
return 100;
} );
@webdados
webdados / multibanco_ifthen_set_on_hold.php
Last active December 15, 2017 12:28
Multibanco IfThenPay - Keep order pending instead of on-hold
<?php
// Multibanco IfThen - Keep order pending instead of on-hold - Be advised that no "new order" email will be sent to the client
add_filter( 'multibanco_ifthen_set_on_hold', '__return_false' );
@webdados
webdados / multibanco_ifthen_cancel_unpaid_orders.php
Created December 15, 2017 18:03
Auto cancellation of WooCommerce Multibanco orders if "Manage stock" and "Hold stock (minutes)" are configured
<?php
// Multibanco IfThen - Cancel orders if "Manage stock" and "Hold stock (minutes)" are configured - Be advised that the Multibanco reference will still be active and can be paid
add_filter( 'multibanco_ifthen_cancel_unpaid_orders', '__return_true' );
@webdados
webdados / cancelled_order_add_customer_email.php
Last active December 16, 2017 03:33
WooCommerce Cancelled orders sent to client also
<?php
add_filter( 'woocommerce_email_recipient_cancelled_order', 'cancelled_order_add_customer_email', 10, 2 );
function cancelled_order_add_customer_email( $recipient, $order ) {
if ( $order ) {
return $recipient . ',' . ( version_compare( WC_VERSION, '3.0', '>=' ) ? $order->get_billing_email() : $order->billing_email );
} else {
return $recipient;
}
}
@webdados
webdados / pending_cancelled_send_an_email_notification.php
Last active December 18, 2017 10:50
Send cancelled pending orders email notifications
<?php
/* WooCommerce emails for cancelled pending orders */
add_action('woocommerce_order_status_pending_to_cancelled', 'pending_cancelled_send_an_email_notification', 10, 2 );
function pending_cancelled_send_an_email_notification( $order_id, $order ) {
if ( version_compare( WC_VERSION, '3.0.8', '>=' ) ) {
// Getting all WC_emails objects
$email_notifications = WC()->mailer()->get_emails();
// Sending the email
$email_notifications['WC_Email_Cancelled_Order']->trigger( $order_id );
@webdados
webdados / woocommerce_helper_suppress_admin_notices.php
Created January 30, 2018 21:51
Hide WooCommerce 3.3 (and above) helper notices, such as extensions updates and connection to WooCommerce.com request
<?php add_filter( 'woocommerce_helper_suppress_admin_notices', '__return_true' ); ?>