Skip to content

Instantly share code, notes, and snippets.

View hedqvist's full-sized avatar

Christopher Hedqvist hedqvist

View GitHub Profile
@hedqvist
hedqvist / functions.php
Created March 13, 2020 08:53
Unifaun - Weight depending on service
<?php
/**
* @snippet WooCommerce - Adds Default weight to parcel depending on service
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.5.3
*/
function redlight_unifaun_minimum_weight_per_service( $shipment, $order) {
foreach( $shipment['parcels'] as $i => $parcel ) {
if( $shipment['parcels'][$i]['weight'] < 0.150 && 'PUA' === $shipment['service']['id'] ){
$shipment['parcels'][$i]['weight'] = 0.150;
@hedqvist
hedqvist / functions.php
Created March 10, 2020 18:29
Swish - Change paymentreference
<?php
/**
* @snippet WooCommerce - Change Reference
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.0
*/
function redlight_swish_custom_reference( $data, $order ) {
$ref = $data['payeePaymentReference'];
$data['payeePaymentReference'] = 'swish-'.$ref;
@hedqvist
hedqvist / functions.php
Created March 7, 2020 12:39
Unifaun - MyPack over 1500
<?php
/**
* @snippet WooCommerce - Change Service to MyPack Collect if order total over 1500
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.0
*/
function redlight_unifaun_mypack_over_1500( $shipment, $order ) {
if($order->get_total() > 1500 ){
$shipment['service']['id'] = 'P19';
}
@hedqvist
hedqvist / functions.php
Created March 4, 2020 19:30
Translate anything
<?php
/**
* @snippet WooCommerce - Translate any text :)
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.2
*/
add_filter('gettext', 'translate_myText');
add_filter('ngettext', 'translate_myText');
function translate_myText($translated) {
$translated = str_ireplace('myTextToReplace', 'myNewText', $translated);
@hedqvist
hedqvist / functions.php
Created March 4, 2020 19:09
Fortnox - Invoice Specials
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Set Terms and PaymentWay if Swish order
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.2
*/
function redlight_fortnox_payment_method_invoicetype($invoice, $order_id) {
$order = new WC_Order($order_id);
$order_payment_method = $order->get_payment_method();
switch( $order_payment_method ) {
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Only create invoices that has payment method Swish
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.2
*/
function redlight_fortnox_create_invoice_for_swish_orders( $create_invoice, $order_id) {
$order = new WC_Order($order_id);
if("redlight_swish-ecommerce" === $order->get_payment_method() ){
$create_invoice = true;
@hedqvist
hedqvist / functions.php
Last active February 26, 2020 09:19
Unifaun - Pacsoft Track and Trace URL
<?php
/**
* @snippet WooCommerce - Sets Tracking URL to Pacsoftonline
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.2
*/
function redlight_pacsoft_tracking_base_url( $url, $order_id ) {
$url = 'https://www.pacsoftonline.com/ext.po';
return $url;
@hedqvist
hedqvist / functions.php
Last active February 25, 2020 19:02
Unifaun - Change Phonenumber
<?php
/**
* @snippet WooCommerce - Sets custom phone in Unifaun
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.2
*/
function redlight_unifaun_custom_phone( $shipment, $order ) {
$shipping_phone= $order->get_meta( '_shipping_phone', true );
if(!empty( $shipping_phone ) ){
@hedqvist
hedqvist / functions.php
Created February 21, 2020 07:23
Orderscanner / Packstation - Change EAN-meta key
<?php
/**
* @snippet WooCommerce - Orderscanner/Packstation - Get barcode from iZettle-plugin
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.0
*/
function redlight_redlight_izettle_barcode( $meta_key ) {
$meta_key = '_izettle_barcode';
@hedqvist
hedqvist / functions.php
Last active February 19, 2020 13:01
Fortnox - Dont prefill from customer card
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Set Blank field in order to prevent details from customer card
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.2
*/
function redlight_fortnox_prevent_autofill($orderData) {
if(empty($orderData['Order']['Address2'])){
$orderData['Order']['Address2'] = "API_BLANK";