Skip to content

Instantly share code, notes, and snippets.

View webdados's full-sized avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / my_apg_sms_send_message.php
Created September 20, 2017 10:11
APG SMS - Only send the new order SMS for certain payment methods
<?php
// New order APG SMS just for Multibanco and Bank Transfer
add_filter( 'apg_sms_send_message', 'my_apg_sms_send_message', 10, 2 );
function my_apg_sms_send_message( $send, $order ) {
$status = is_callable( array( $order, 'get_status' ) ) ? $order->get_status() : $order->status;
//New order? (Not the English synthpop band...)
if ( $status == 'on-hold' || $status == 'pending' ) {
$payment_method = is_callable( array( $order, 'get_payment_method' ) ) ? $order->get_payment_method() : $order->payment_method; //WC >=3.0 or older?
switch ($payment_method) {
@webdados
webdados / apg_sms_message_bank_transfer.php
Last active September 20, 2017 10:28
Special Bank Transfer instructions for New Order emails no APG SMS (using the %bacs_instructions% tag on the sms template)
<?php
// Bank Transfer details
add_filter('apg_sms_message', 'apg_sms_message_bank_transfer', 999, 2);
function apg_sms_message_bank_transfer( $message, $order_id ) {
$inst = '';
$order = new WC_Order($order_id);
$status = is_callable( array( $order, 'get_status' ) ) ? $order->get_status() : $order->status; //WC >=3.0 or older?
//New order? (Not the English synthpop band...)
if ( $status == 'on-hold' || $status == 'pending' ) {
$payment_method = is_callable( array( $order, 'get_payment_method' ) ) ? $order->get_payment_method() : $order->payment_method; //WC >=3.0 or older?
@webdados
webdados / fb_og_image_additional.php
Created September 26, 2017 09:25
Using the fb_og_image_additional filter on Facebook Open Graph, Google+ and Twitter Card Tags for WordPress
<?php
add_filter( 'fb_og_image_additional', 'extra_preview_images' );
function extra_preview_images( $fb_image_additional ) {
//You could/should use your own logic to decide which images to return. This example only shows you the structure of the array you should return.
if ( !is_array( $fb_image_additional ) ) {
$fb_image_additional = array();
}
$fb_image_additional[] = array(
'fb_image' => 'https://domain.com/wp-content/uploads/og_image2.jpg',
@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 / woocommerce_catalog_mode.php
Last active April 10, 2019 11:52
WooCommerce easy "Catalog mode" - Disable all products from being purchasable
<?php
// Disable all products from being purchasable (Yes, that's it...) - Add this to your (child) theme functions.php file
add_filter( 'woocommerce_is_purchasable', '__return_false' );
@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_show_prices_with_or_without_tax.php
Last active April 6, 2021 19:34
Show WooCommerce prices with or without tax / VAT depending on user profile / option
<?php
/* WooCommerce prices shown with or without tax depending on client type */
add_filter( 'option_woocommerce_tax_display_shop', 'woocommerce_show_prices_with_or_without_tax' );
add_filter( 'option_woocommerce_tax_display_cart', 'woocommerce_show_prices_with_or_without_tax' );
function woocommerce_show_prices_with_or_without_tax( $option ) {
if ( is_user_logged_in() ) {
//Client type from user_meta or profile or whatever...
//Example: $client_hide_tax = get_user_meta( get_current_user_id(), 'client_type', true ) ? true : false;
//Example to create this field on registration: https://gist.github.com/webdados/c8dbbe7ccdea3463312e5b865ad92d92
@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 / 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