Skip to content

Instantly share code, notes, and snippets.

View NiklasHogefjord's full-sized avatar

Niklas Högefjord NiklasHogefjord

View GitHub Profile
/**
* WooCommerce - Klarna payment gateway
* Filter the label for Klarna Invoice payment method, displayed in the selectbox in the description field in WooCommerce Checkout page.
**/
add_filter( 'klarna_invoice_label', 'my_klarna_invoice_label', 10, 2);
function my_klarna_invoice_label( $invoice_string, $country ) {
switch ( $country ) {
case 'DK' :
@NiklasHogefjord
NiklasHogefjord / wc-specter-send-custom-customer-data.php
Last active April 12, 2016 07:04
Modify customer data sent to Specter on a new order submission
<?php
/**
* Filter hook wc_specter_send_custom_customer_data
* Modify customer data sent to Specter on new order submission.
*
**/
add_filter( 'wc_specter_send_custom_customer_data', 'my_wc_specter_send_custom_customer_data', 10, 2 );
function my_wc_specter_send_custom_customer_data( $params, $order ) {
@NiklasHogefjord
NiklasHogefjord / wc-klarna-show-refunded-status.php
Created April 15, 2016 06:50
Display "Refunded" as an order status in the dropdown for KCO orders. This is removed by the Klarna extension by default.
<?php
/**
* Display "Refunded" as an order status in the dropdown for KCO orders.
* This is removed by the Klarna extension by default because Klarna wants
* the refunds to be handled in WooCommerce and Klarna at the same time.
**/
add_filter( 'klarna_checkout_hide_refunded_status', '__return_false' );
@NiklasHogefjord
NiklasHogefjord / wc-specter-send-custom-product-data
Last active April 19, 2016 14:06
Add custom parameters to WooCommerce products exported to Specter
/**
* Filter hook wc_specter_send_custom_product_data
* Add custom parameters to products sent to Specter.
* The product data will be passed to Specter both on single product update (save_post)
* and on manually triggered product exports (from the Specter settings page).
* Contact Specter for detailed information on what parameters their system accepts.
**/
add_filter( 'wc_specter_send_custom_product_data', 'my_custom_product_data', 10, 2 );
@NiklasHogefjord
NiklasHogefjord / wc-klarna-send-extra-merchant-data.php
Last active July 13, 2016 09:01
Makes it possible for merchants to sent specific information about products or customers, in Klarna checkout orders, that Klarna might require. Use this code in a separate plugin or via your themes functions.php
<?php
/**
* WooCommerce - Klarna payment gateway (Klarna Checkout)
* Filter Create order & Update order for adding EMD (Extra Merchant Data) sent to Klarna.
*
* Learn more about available attatchmenat types here: https://developers.klarna.com/en/no/kco-v2/checkout-api/attachments
**/
// New order ($create)
add_filter('kco_create_order', 'my_kco_create_order');
<?php
/**
* Filter hook wc_specter_send_order_data
* Modify order data sent to Specter on new order submission.
*
**/
add_filter( 'wc_specter_send_order_data', 'my_wc_specter_send_order_data', 10, 2 );
function my_wc_specter_send_order_data( $params, $order ) {
@NiklasHogefjord
NiklasHogefjord / wc-specter-send-custom-product-data.php
Last active November 11, 2016 08:08
Modify the product data sent to Specter when saving a product in WooCommerce. Product sync WooCommerce to Specter must be activated in the Specter plugin settings.
<?php
add_filter( 'wc_specter_send_custom_product_data', 'my_custom_product_data', 10, 3 );
function my_custom_product_data( $params, $product, $is_variation = false ) {
/**
* $params is the product data stored as an array.
* $product is the product object. Product variation object if this is a product variation.
* $is_variation is true/false depending on if this is a product variation or not.
*/
@NiklasHogefjord
NiklasHogefjord / wc-trim-zeros-in-price-decimals.php
Created November 14, 2016 14:20
Add this code in your themes functions.php or as a separate plugin.
<?php
/**
* Trim zeros in price decimals in WooCommerce.
* For instance $200.00 is displayed as $200.
**/
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
@NiklasHogefjord
NiklasHogefjord / woocommerce-dibs-paytypes
Created October 1, 2014 12:58
WooCommerce, DIBS Payment Gateway - Filter the paytype sent to DIBS
/**
* WooCommerce - DIBS payment gateway
* Filter the paytype sent to DIBS
*
**/
add_filter('woocommerce_dibs_paytypes', 'myprefix_dibs_paytypes');
function myprefix_dibs_paytypes( $paytypes ) {
// Multiple paytypes are added comma separated.
add_filter( 'woocommerce_get_checkout_url', 'krokedil_change_checkout_url', 30 );
function krokedil_change_checkout_url( $url ) {
$allowed_countries = array( 'SE', 'NO', 'FI', 'DE', 'DK', 'AT', 'UK', 'US' );
$customer_country = WC()->customer->shipping_country;
if( !in_array( $customer_country , $allowed_countries ) ) {
$url = wc_get_page_permalink( 'checkout' );
}
return $url;