Skip to content

Instantly share code, notes, and snippets.

View webdados's full-sized avatar

Marco Almeida webdados

View GitHub Profile
@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 / 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;
}
@webdados
webdados / testing_multibanco_ifthen_base_ent_subent.php
Created September 10, 2018 10:13
Multibanco IfThen - Use specific Entity and Subentity for some specific order details
<?php
// Multibanco IfThen - Use specific Entity and Subentity for some specific order details (Example: depending on the delivery method, or the items bought, the payment must be made with different Ent/Subent)
add_filter( 'multibanco_ifthen_base_ent_subent', 'testing_multibanco_ifthen_base_ent_subent', 10, 2 );
function testing_multibanco_ifthen_base_ent_subent( $base, $order ) {
//$base is a array with 'ent' and 'subent' keys / values
//Test whatever you want here related to the $order object
if ( true ) {
@webdados
webdados / .htacess
Created October 8, 2018 12:10
.htaccess rules to redirect http to http
# Do NOT use this rules unless you are absolutely sure you do not have any mixed contents issues, or you may be masquerading them
# Redirect from http to https without www
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
@webdados
webdados / wpml-unregister-string.php
Created October 11, 2018 11:44
Unregister all strings of a specific textdomain from WPML
<?php
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
$domain = 'woocommerce'; //Change textdomain as needed
$arr = array();
$sql = sprintf( "SELECT id FROM ix_icl_strings WHERE context='%s'", $domain );
$strings = $wpdb->get_results( $sql );
@webdados
webdados / multibanco_ifthen_thankyou_instructions_table_html.php
Created November 2, 2018 19:52
multibanco_ifthen_thankyou_instructions_table_html filter example
<?php
// Multibanco IfThen - Thank you page payment instructions filter
add_filter( 'multibanco_ifthen_thankyou_instructions_table_html', 'my_multibanco_ifthen_thankyou_instructions_table_html', 1, 5 );
function my_multibanco_ifthen_thankyou_instructions_table_html( $html, $ent, $ref, $order_total, $order_id ) {
ob_start();
?>
<h2>Multibanco payment instructions for Order #<?php echo $order_id; ?></h2>
<p>
<b>Entity:</b> <?php echo $ent; ?>
<br/>
@webdados
webdados / multibanco_add_to_quotes.php
Last active December 9, 2018 10:56
Adicionar dados de pagamento Multibanco a Orçamentos e Proformas
<?php
// Adicionar campo no plugin Multibanco
add_filter( 'multibanco_ifthen_multibanco_settings_fields', 'multibanco_add_quotes_option' );
function multibanco_add_quotes_option( $settings ) {
$settings['ix_quotes_title'] = array(
'type' => 'title',
'title' => 'Invoicing with InvoiceXpress for WooCommerce - Pro',
);
$settings['ix_quotes'] = array(
'type' => 'checkbox',