Skip to content

Instantly share code, notes, and snippets.

Niklas Högefjord NiklasHogefjord

Block or report user

Report or block NiklasHogefjord

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@NiklasHogefjord
NiklasHogefjord / wc-specter-remove-article-type-in-product-sync.php
Created May 15, 2018
Remove articleType as parameter sent to Specter on product updates. This can be useful if some articles are marked as "paketartiklar" in Specter (since WooCommerce don't have support for that).
View wc-specter-remove-article-type-in-product-sync.php
<?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.
*/
// Unset articleType type so we don't send that to Specter when product is updated in WooCommerce.
@NiklasHogefjord
NiklasHogefjord / wc-kco-v2-required-checkbox.php
Last active May 11, 2018
Display a checkbox in KCO that is required to check to be able to complete purchase. This is used for the WooCommerce Klarna gateway (v2).
View wc-kco-v2-required-checkbox.php
<?php
// Add a cehckbox to KCO iframe that is required to check before the purchase can be completed
add_filter('kco_create_order', 'krokedil_add_required_checkbox');
add_filter('kco_update_order', 'krokedil_add_required_checkbox');
function krokedil_add_required_checkbox( $create ) {
$create['options']['additional_checkbox']['text'] = 'I agree to the <a href="https://example.com/terms" target="_blank">terms</a> and data policy.';
$create['options']['additional_checkbox']['checked'] = false;
$create['options']['additional_checkbox']['required'] = true;
return $create;
}
@NiklasHogefjord
NiklasHogefjord / wc-specter-add-customer-note-as-published-comment.php
Created Apr 4, 2018
Add WooCommerce customer note to publishedComment in order data sent to Specter
View wc-specter-add-customer-note-as-published-comment.php
<?php
/**
* Filter hook wc_specter_published_comment
* Modify publishedComment sent to Specter on new order submission.
* publishedComment is displayed on the order/packing slip that can be sent to the customer.
*
**/
add_filter( 'wc_specter_published_comment', 'my_wc_specter_published_comment', 10, 2 );
function my_wc_specter_published_comment( $published_comment, $order ) {
@NiklasHogefjord
NiklasHogefjord / wc-specter-order-filters.php
Last active Sep 22, 2017
WooCommerce Specter order filters - modify order data sent from WooCommerce to Specter
View wc-specter-order-filters.php
<?php
/**
* Filter hook wc_specter_internal_comment
* Modify internalComment sent to Specter on new order submission.
* internalComment is displayed in Specter for the merchant but not on the order/packing slip that can be sent to the customer.
*
**/
add_filter( 'wc_specter_internal_comment', 'my_wc_specter_internal_comment', 10, 2 );
function my_wc_specter_internal_comment( $customer_note, $order_id ) {
// Tänk på att $customer_note kan innehålla kundens notering från kassan
@NiklasHogefjord
NiklasHogefjord / class-wcml-klarna-gateway.php
Last active Aug 16, 2017
Updated compatibility file for WCML (https://wordpress.org/plugins/woocommerce-multilingual/) used to get Klarna Checkout payment gateway (https://woocommerce.com/products/klarna) to work with WCML/WPML multi currencies in WooCommerce.
View class-wcml-klarna-gateway.php
<?php
class WCML_Klarna_Gateway{
public function add_hooks(){
add_filter( 'wcml_multi_currency_ajax_actions', array( $this, 'ajax_action_needs_multi_currency' ) );
}
@NiklasHogefjord
NiklasHogefjord / wc-kco-change-klarna-country.php
Created Jul 24, 2017
Filter country sent to Klarna to modify which checkout iframe should be displayed for the customer. This could be useful when selling to multiple Euro-countries (Finland, Germany, Netherlands, Austria) and have a separate plugin for the customer so select their shipping country (or have Geo location enabled). In this case you don't have to use t…
View wc-kco-change-klarna-country.php
<?php
/**
* WooCommerce - Klarna payment gateway
* Filter the country sent to Klarna.
**/
add_filter( 'klarna_country', 'my_klarna_country' );
function my_klarna_country( $country ) {
if( WC()->customer ) {
if ( 'EUR' == get_woocommerce_currency() ) {
@NiklasHogefjord
NiklasHogefjord / wc-kco-validate-customer-age.php
Last active Jan 8, 2018
Code example on how to only accept purchases from people over 18 years of age with Klarna Checkout and WooCommerce
View wc-kco-validate-customer-age.php
<?php
/**
* WooCommerce - Klarna payment gateway
* Only accept purchases from customer over 18 years of age.
**/
// Edit the order data sent to Klarna to make 'Date of birth' a mandatory field in the KCO iframe
add_filter('kco_create_order', 'my_kco_create_order');
function my_kco_create_order( $create ) {
$create['options']['national_identification_number_mandatory'] = true;
View wc-kco-date-of-birth-mandatory.php
/**
* WooCommerce - Klarna payment gateway
* Filter Create order for making date of birth a mandatory field in Klarna Checkout iframe.
**/
// New order ($create)
add_filter('kco_create_order', 'my_kco_create_order');
function my_kco_create_order( $create ) {
$create['options']['national_identification_number_mandatory'] = true;
View wc-klarna-change-checkout-url.php
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;
@NiklasHogefjord
NiklasHogefjord / wc-trim-zeros-in-price-decimals.php
Created Nov 14, 2016
Add this code in your themes functions.php or as a separate plugin.
View wc-trim-zeros-in-price-decimals.php
<?php
/**
* Trim zeros in price decimals in WooCommerce.
* For instance $200.00 is displayed as $200.
**/
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
You can’t perform that action at this time.