Skip to content

Instantly share code, notes, and snippets.

View NiklasHogefjord's full-sized avatar

Niklas Högefjord NiklasHogefjord

View GitHub Profile
@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.
*/
<?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-klarna-change-mandatory-fields-and-fetch-order-data-php
Last active January 8, 2018 13:26
Filter Create order & Update order sent to Klarna to change mandatory fields in the checkout iframe (Date of birth & Title). Also fetching order data returned from Klarna after a successful payment and updating the local WooCommerce order.
<?php
/**
* WooCommerce - Klarna payment gateway (Klarna Checkout)
* Filter Create order & Update order sent to Klarna to change mandatory fields in the checkout iframe (Date of birth & Title).
* Also fetching order data returned from Klarna after a successful payment and updating the local WooCommerce order.
*
* Learn more about available params in order object sent to Klarna here:
* V2 - https://developers.klarna.com/en/se/kco-v2/checkout-api
* V3 - https://developers.klarna.com/api/#checkout-api
*
@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');
@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' );
/**
* 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-klarna-modify-kco-checkout-url.php
Last active March 3, 2016 14:46
Change checkout URL for Klarna Checkout if user isn't from a specific country. Can be useful if selling to multiple countries and you want to redirect customers that can't pay with KCO directly to the standard WooCommerce Checkout. Requires Default Customer Address to be set to Geolocate in WooCommerce settings.
<?php
/*
Plugin Name: Modify Klarna Checkout URL
Plugin URI: http://krokedil.com
Description: Change checkout URL for Klarna Checkout if user isn't from a specific country
Version: 1.0
Author: Krokedil
Author URI: http://krokedil.com
*/
add_filter( 'woocommerce_get_checkout_url', 'krokedil_change_checkout_url', 30 );
@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 / modify-woocommerce-thankyou-page-for-dibs-wpml.php
Last active August 10, 2017 09:42
Adjust the url specified in WooCommerce function get_checkout_order_received_url() so that the correct thankyou page set in WPML is used. // From version 2.4.5 of the DIBS plugin this code is no longer needed. The plugin now have built in support for redirecting to the correct page if using WPML.
<?php
/*
Plugin Name: Correct thankyou page for DIBS/WPML
Plugin URI: http://krokedil.com
Description: Adjust the url specified in WooCommerce function get_checkout_order_received_url() so that the correct thankyou page set in WPML is used.
Version: 1.0
Author: Krokedil
Author URI: http://krokedil.com
*/
@NiklasHogefjord
NiklasHogefjord / klarna-checkout-extra-fields.php
Last active September 16, 2019 13:19
Add custom input fields to Klarna Checkout page. Added via shortcode [woocommerce_klarna_checkout_extra_fields]. Saved as post_meta to the order directly on .blur via ajax.
<?php
/**
* Plugin Name: Klarna Checkout Extra Fields
* Plugin URI: http://krokedil.com
* Description: Add custom input fields to Klarna Checkout page. Added via shortcode [woocommerce_klarna_checkout_extra_fields]. Saved as post_meta to the order directly on .blur via ajax.
* Version: 1.1
* Author: Krokedil
* Author URI: http://krokedil.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt