Skip to content

Instantly share code, notes, and snippets.

/**
* Hide R1 field for customers outside HR
**/
add_action( 'woocommerce_after_checkout_form', 'mx_show_r1_4hr' );
function mx_show_r1_4hr(){
if ( is_checkout() ) {
?>
<script>
jQuery(document).ready(function($){
@blivic
blivic / mx_text_bellow_product_thumbs.php
Last active November 5, 2019 11:35
Add text bellow product thumbnails (Single product page)
function mx_text_bellow_product_thumbs() {
echo '<div class="woocommerce-text-under-thumbs" style="background: #fdfd5a; padding: 1em 2em; clear: left;float: left; max-width: 300px; font-size: 0.7em;">';
echo '<span>ADD TEXT, IMAGES AND ANY HTML</span>';
echo '</div>';
}
add_action( 'woocommerce_before_single_product_summary', 'mx_text_bellow_product_thumbs' , 21);
@blivic
blivic / mx_local_pickup_instructions_order_email.php
Created August 22, 2019 12:44
WooCommerce - Add instructions for local pickup shipping method in processing and completed email notifications
function mx_local_pickup_instructions_order_email( $order, $sent_to_admin, $plain_text, $email ) {
// Only for processing and completed email notifications to customer
if( ! ( 'customer_processing_order' == $email->id || 'customer_completed_order' == $email->id ) ) return;
foreach( $order->get_items('shipping') as $shipping_item ){
$shipping_rate_id = $shipping_item->get_method_id();
$method_array = explode(':', $shipping_rate_id );
$shipping_method_id = reset($method_array);
if( 'local_pickup' == $shipping_method_id ){
?><h2>Ime trgovine</h2>
@blivic
blivic / mx_local_pickup_instructions_thank_you_page.php
Last active August 22, 2019 12:48
WooCommerce - Add instructions for local pickup shipping method on thank you page
function mx_local_pickup_instructions_thank_you_page( $order_id ) {
$order = wc_get_order( $order_id );
$order_methods = array_map( function( $shipping ) { return $shipping->get_method_id(); }, $order->get_shipping_methods() );
if ( in_array( 'local_pickup', $order_methods ) ) {
?><h2>Ime trgovine</h2>
<p>Naručene artikle možete preuzeti u našoj trgovini.</p>
<p>
Moja ulica b.b.<br/>
52100, Pula<br/>
+385 99 123456<br/><br/>
@blivic
blivic / mx-woo-bacs-instructions-order-number.php
Last active January 12, 2023 09:43
WooCommerce - better BACS payment instructions
<?php
/*
Plugin Name: MX Woo BACS
Plugin URI: https://media-x.hr
Description: Poboljšane upute za plaćanje putem direktne bankovne transakcije
Version: 1.0
Author: Media X
WC requires at least: 3.0
WC tested up to: 3.6.4
Author URI: http://media-x.hr
@blivic
blivic / display_size_attribute_in_shop.php
Last active June 20, 2019 15:12
Display available sizes on shop page
<?php
/**
* DO NOT copy the opening php tag
* check if you're using the correct attribute slug
*/
add_action('woocommerce_after_shop_loop_item','display_size_attribute_in_shop');
function display_size_attribute_in_shop() {
global $product;
if( $product->is_type('variable') ){
@blivic
blivic / mx-cod-fee.php
Created June 7, 2019 08:27
Adding a fee if chosen payment method is COD
add_action( 'woocommerce_cart_calculate_fees', 'mx_add_cod_fee', 20, 1 );
function mx_add_cod_fee( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$your_payment_id = 'cod'; // Metoda plaćanja
$fee_amount = 6; // Naknada
$chosen_payment_method_id = WC()->session->get( 'chosen_payment_method' );
if ( $chosen_payment_method_id == $your_payment_id ) {
$fee_text = __( "Troškovi plaćanja pouzećem", "woocommerce" );
@blivic
blivic / admin_email_subject_with_product_names.php
Created May 4, 2019 16:36
Adding product title(s) to new order admin email
function admin_email_subject_with_product_names( $subject, $order ) {
$products_names = array();
foreach ( $order->get_items() as $item ) {
$products_names[] = $item->get_name();
}
return sprintf( '[%s] Nova narudžba kupca (#%s) - %s',
wp_specialchars_decode(get_option('blogname'), ENT_QUOTES),
$order->get_id(),
@blivic
blivic / mx_price_per_installments_w_fee.php
Last active March 18, 2019 12:46
Show amount for 3, 6 and 12 installments (with percentage fee), under regular price
add_action( 'woocommerce_single_product_summary', 'mx_price_per_installments_w_fee', 11 );
function mx_price_per_installments_w_fee() {
global $product;
$price = $product->get_price();
$threeinstallments = 3;
$sixinstallments = 6;
$twelveinstallments = 12;
$fee = (3.5/100) * $price;
@blivic
blivic / mx_price_per_installments.php
Last active March 18, 2019 12:44
Show amount for 3, 6 and 12 installments, under regular price
add_action( 'woocommerce_single_product_summary', 'mx_price_per_installments', 11 );
function mx_price_per_installments() {
global $product;
$price = $product->get_price();
$threeinstallments = 3;
$sixinstallments = 6;
$twelveinstallments = 12;