Skip to content

Instantly share code, notes, and snippets.

View finalwebsites's full-sized avatar

Olaf Lederer finalwebsites

View GitHub Profile
@finalwebsites
finalwebsites / gratis_verzending.php
Created March 26, 2024 18:46
WooCommerce: Overige verzendmethoden verbergen indien gratis verzending van toepassing is
<?php
function fws_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
@finalwebsites
finalwebsites / functions.php
Last active January 12, 2024 08:59
Child theme for WordPress and OceanWP
<?php
add_action( 'wp_enqueue_scripts', 'fw_theme_enqueue_styles', 100 );
function fw_theme_enqueue_styles() {
$dependencies = array(); // add here other theme handles, for example from the parent theme or WooCommerce
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', $dependencies, '1.0.0' );
}
@finalwebsites
finalwebsites / extra_product_tabs.php
Last active December 30, 2023 20:19
Additional product tabs for your WooCommerce product pages
<?php
add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tabs' );
function woo_custom_product_tabs( $tabs ) {
// Shipment info tab
$tabs['fw_shipment_tab'] = array(
'title' => __( 'Shipment info', 'woocommerce' ),
'priority' => 100, // use a higher value and move the tab to the end
'callback' => 'fw_shipment_tab_content'
);
}
@finalwebsites
finalwebsites / functions.php
Created November 5, 2023 13:48
Set image ALT Tag after upload via the WordPress media library
<?php
add_action( 'add_attachment', 'fws_set_image_alt_after_upload' );
function fws_set_image_alt_after_upload( $post_ID ) {
if ( wp_attachment_is_image( $post_ID ) ) {
$post = get_post( $post_ID );
update_post_meta( $post_ID, '_wp_attachment_image_alt', $post->post_title );
}
}
@finalwebsites
finalwebsites / wordpress-faq-shortcode.php
Last active October 20, 2023 18:38
WordPress FAQ shortcode with stucutured data notations
<?php
function fws_create_faq_list($atts) {
$atts = shortcode_atts(
array(
'soort' => ''
),
$atts
);
$html = '';
@finalwebsites
finalwebsites / functions.php
Last active October 20, 2023 18:20
Add aan extra description to your WooCommerce product archive with ACF
<?php
/*
Place this code in your functions.php file to show a short description before the grid on product categorie archive pages.
Disclaimer: Use this code snippet with extreme care and at your own risk.
*/
add_action('woocommerce_archive_description', function() {
if (!is_paged() && is_product_category()) {
if (function_exists('get_field')) {
$term_id = get_queried_object()->term_id;
echo '
@finalwebsites
finalwebsites / hide_coupons.php
Created October 20, 2023 14:14
Disable the coupon form on the checkout page from WooCommerce
<?php
// place this code inside the functions.php file from your child code.
function fw_disable_coupon_field_on_checkout( $enabled ) {
if ( is_checkout() ) {
$enabled = false;
}
return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'fw_disable_coupon_field_on_checkout' );
@finalwebsites
finalwebsites / Elementor_Form_to_EmailOctopus_API.php
Last active October 11, 2023 10:20
Elementor form action hook to send suscribers to the EmailOctopus API
<?php
// place this code into your functions.php file
// Check the notes below for further instructions
// add here the EmailOctopus API key
define('EO_API', '00000000-0000-0000-0000-000000000000');
// get the fields from a specific list from EmailOctopus
function get_emailoctopus_list_fields($list_id) {
@finalwebsites
finalwebsites / add-content-storefront.php
Last active October 8, 2023 14:51
Voorbeelden voor WordPress action en filter hooks
<?php
add_action( 'storefront_header', 'ctheme_storefront_header_content', 40 );
function ctheme_storefront_header_content() {
echo '
<div class="header-usp">
Gratis verzending - Voor 14 uur besteld? Volgende dag bezorgt.
</div>';
}
@finalwebsites
finalwebsites / wc-replace-add-to-cart-btn.php
Created September 29, 2023 12:27
WordPress hooks add-to-cart button replacement
<?php
add_filter( 'woocommerce_is_purchasable', '__return_false'); // disable the default button
add_action( 'woocommerce_single_product_summary', 'fw_add_offer_request_button', 30 );
function fw_add_offer_request_button(){
echo '<button>Offerte aanvragen</button>';
}