Skip to content

Instantly share code, notes, and snippets.

View mircobabini's full-sized avatar

Mirco Babini mircobabini

View GitHub Profile
<?php
add_action( 'wpo_wcpdf_billing_address', function ( $billing_address, $invoice ) {
if ( ! empty( $invoice ) ) {
$billing_address_prefix = '';
// billing_company
$company_name = trim( $invoice->order->get_meta( '_billing_company', true, 'view' ) );
if ( ! empty( $company_name ) ) {
$billing_address_prefix .= "<b>$company_name</b><br>";
}
@mircobabini
mircobabini / wc-wpo-wcpdf-billing-address-company-vat-advanced.php
Last active February 14, 2023 17:46
In order to use the "additional" fields feature, the premium version of the plugin is required. Check the simple version otherwise: https://gist.github.com/mircobabini/64ead066b22575f6948d133c82500555
<?php
add_action( 'wpo_wcpdf_billing_address', function ( $billing_address, $invoice ) {
if ( ! empty( $invoice ) ) {
$customer_type = $invoice->order->get_meta( '_additional_wooccm0', true, 'view' );
if ( 'Azienda' === $customer_type ) {
$company_name = $invoice->order->get_meta( '_additional_wooccm1', true, 'view' );
$company_vat = $invoice->order->get_meta( '_additional_wooccm2', true, 'view' );
$billing_address_prefix = "";
<?php
define( 'INVOICE_GENERATION_MINIMUM_SUBTOTAL', 100 ); // se subtotale >= X€ IVA ESCUSA, allora genero la fattura
add_filter( 'wpo_wcpdf_document_is_allowed', function ( $allowed, $document ) {
if ( ! $document->exists() && ! empty( $order = $document->order ) ) {
if ( ! is_callable( array( $order, 'get_subtotal' ) ) ) {
return false;
}
// check order total & setting
$order_subtotal = $order->get_subtotal();
@mircobabini
mircobabini / wc-sell-or-ship-to-specific-countries-europe.sql
Last active February 9, 2023 08:27 — forked from pascalknecht/query.sql
WooCommerce sell/ship EU Countries only (small area, extended area or the whole continent)
# Sell to specific EU countries only
UPDATE `wp_options` SET `option_value`='specific' WHERE option_name = 'woocommerce_allowed_countries';
UPDATE `wp_options` SET `option_value`='a:30:{i:0;s:2:"AT";i:1;s:2:"BE";i:2;s:2:"BG";i:3;s:2:"HR";i:4;s:2:"CY";i:5;s:2:"CZ";i:6;s:2:"DK";i:7;s:2:"EE";i:8;s:2:"FI";i:9;s:2:"FR";i:10;s:2:"DE";i:11;s:2:"GR";i:12;s:2:"HU";i:13;s:2:"IE";i:14;s:2:"IM";i:15;s:2:"IT";i:16;s:2:"JE";i:17;s:2:"LV";i:18;s:2:"LT";i:19;s:2:"LU";i:20;s:2:"MT";i:21;s:2:"NL";i:22;s:2:"PL";i:23;s:2:"PT";i:24;s:2:"RO";i:25;s:2:"SK";i:26;s:2:"SI";i:27;s:2:"ES";i:28;s:2:"SE";i:29;s:2:"GB";}' WHERE option_name = 'woocommerce_specific_allowed_countries';
# Ship to specific EU countries only
UPDATE `wp_options` SET `option_value`='specific' WHERE option_name = 'woocommerce_ship_to_countries';
UPDATE `wp_options` SET `option_value`='a:30:{i:0;s:2:"AT";i:1;s:2:"BE";i:2;s:2:"BG";i:3;s:2:"HR";i:4;s:2:"CY";i:5;s:2:"CZ";i:6;s:2:"DK";i:7;s:2:"EE";i:8;s:2:"FI";i:9;s:2:"FR";i:10;s:2:"DE";i:11;s:2:"GR";i:12;s:2:"HU";i:13
<?php
/**
* Plugin Name: SED Web - Scheduled Post Trigger
* Description: Publishes scheduled posts that were missed by cron at defined interval
* Plugin URI:
* Version: 1.4.0
* Requires at least: 4.9
* Requires PHP: 5.6
* License: GPLv2 or later
* Author: SED Web
{
"name": "vendor_name/site-composer-based",
"description": "description",
"minimum-stability": "stable",
"license": "proprietary",
"authors": [
{
"name": "mircobabini",
"email": "email@example.com"
}
<?php
/**
* Grant access to the back-end to certain user roles
*
* @param bool $prevent_admin_access
*
* @return bool
*/
function pmpro_grant_admin_access_to_dataanalyst( $prevent_admin_access ) {
if ( current_user_can( 'dataanalyst' ) ) {
@mircobabini
mircobabini / variation-duplicator-for-woocommerce-disable-image-duplicator.php
Last active June 14, 2022 09:12
UPDATE: useless from 2.0.4+ thanks to the new filter disable_variation_duplicator_for_woocommerce_image_clone
<?php
/**
* Plugin Name: Duplicate Variations for WooCommerce (Disable Image Duplicator)
* Description: Disattiva la funzionalità di "image duplicator" che rallenta il loading delle variazioni
* Author: Mirco Babini
* Domain Path: /languages
* Version: 2.0.3
* Author URI: https://sedweb.com/
*/
add_action( 'variation_duplicator_for_woocommerce_variation_image_clone_loaded', function ( $instance ) {
@mircobabini
mircobabini / my-pmpro-reset-cron-schedules.php
Last active March 11, 2022 17:26 — forked from sc0ttkclark/my-pmpro-reset-cron-schedules.php
Reset the Cron Schedules for Paid Memberships Pro. The single-use version can be found at: https://gist.github.com/sc0ttkclark/bd319a47656b786ccee3eca6f2dc4a9a
<?php
/**
* Reset the Cron Schedules for Paid Memberships Pro.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
<?php
/**
* Display messages of the Original Price, Discounted Price and Amount Saved when discount code is applied to PMPro order.
* Add this code recipe to a PMPro Customization Plugin - Display messages of the Original Price, Discounted Price and Amount Saved when discount code is applied to PMPro order
* Various classes added to strings to allow for styling - ".pmpro-discorig-message", ".pmpro-orginal-price", ".pmpro-discount-price", ".pmpro-save-price"
*
* [my_pmpro_applydiscountcode_return_js] Display original price and discount when a discount code is applied.
*
* @param string $discount_code [description]