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 August 11, 2020 14:04
Fortnox - Project code
<?php
/**
* @snippet WooCommerce -Fortnox - Set Project
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.1.1
*/
function redlight_fortnox_order_project( $orderData, $order_id) {
switch( get_site_url() ){
case 'https://www.example.com':
@hedqvist
hedqvist / functions.php
Created August 11, 2020 13:22
Unifaun - Force 250g on all parcels
/**
* @snippet WooCommerce - Sets Weight on Parcels (Overwrites weight total)
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.4.0
*/
function redlight_unifaun_parcel_weight( $shipment, $order) {
foreach( $shipment['parcels'] as $i => $parcel ) {
$shipment['parcels'][$i]['weight'] = 0.250;
}
@hedqvist
hedqvist / functions.php
Created August 6, 2020 17:07
BankID - Dont display Cart Item Data
<?php
/**
* @snippet WooCommerce - BankID - Dont display "Age verification: Via BankID" in cart and meta.
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.1.1
*/
add_filter( 'redlight_bid_woocommerce_display_cart_item_data', '__return_false' );
@hedqvist
hedqvist / functions.php
Created July 27, 2020 09:12
Fortnox - South Korea Temp Fix
<?php
/**
* @snippet WooCommerce -Fortnox - Solve South Korea until Fortnox fixes backend
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.1.0
*/
function redlight_fortnox_south_korea( $orderData, $order_id) {
//$order = new WC_Order($order_id);
if( $orderData['Order']['Country'] == 'South Korea' ){
$orderData['Order']['Country'] = 'Korea, Republic of';
@hedqvist
hedqvist / functions.php
Last active June 29, 2020 08:26
WooCommerce - Add Custom Status
<?php
/**
* @snippet WooCommerce - Add custom status
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.1.1
*/
add_filter('wc_order_statuses', 'add_custom_order_status' );
public function add_custom_order_status( $order_statuses ){
$order_statuses['wc-fetched'] = __('Fetched');
return $order_statuses;
<?php
/**
* @snippet WooCommerce - Unifaun - Set receiverReference tp order ID
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.1.1
*/
function redlight_unifaun_receiver_reference( $shipment, $order ) {
$shipment['receiverReference'] = $order->get_order_number();
return $shipment;
}
@hedqvist
hedqvist / functions.php
Last active March 9, 2021 16:43
Unifaun - DHL Addon
<?php
/**
* @snippet WooCommerce - Adds ADDON to Shipment
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.2.0
*/
function redlight_unifaun_dhl_addon( $shipment, $order ) {
// Only AEX
if( 'AEX' === $shipment['service']['id'] ){
$shipment['service']['addons'][] = array(
@hedqvist
hedqvist / functions.php
Created June 17, 2020 08:27
BankID - Age Limit on all Products
<?php
/**
* @snippet WooCommerce - BankID plugin by Redlight Media - Add Age control on all products
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.2.0
*/
add_action( 'woocommerce_add_cart_item_data', 'limit_all_products', 10, 3 );
function limit_all_products( $cart_item_data, $product_id, $variation_id ) {
$cart_item_data['is_age_verification_required'] = 'yes';
return $cart_item_data;
@hedqvist
hedqvist / functions.php
Created June 11, 2020 08:04
Fortnox - Only Bookeep orders that has Swish as Payment Method
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Bookeep only Swish Orders
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.2.0
*/
function redlight_fortnox_bookeep_swish($should_bookeep,$order_id, $updated_order) {
$order = wc_get_order($order_id);
$order_payment_method = $order->get_payment_method();
switch( $order_payment_method ) {
@hedqvist
hedqvist / functions.php
Last active February 7, 2022 10:29
Fortnox - Swish Payments as Cash Invoice
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Set Terms and PaymentWay if Swish or Stripe order
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.2.0
*/
function redlight_fortnox_swish_invoicetype($invoice, $order_id) {
$order = wc_get_order($order_id);
$order_payment_method = $order->get_payment_method();
switch( $order_payment_method ) {