Skip to content

Instantly share code, notes, and snippets.

View finalwebsites's full-sized avatar

Olaf Lederer finalwebsites

View GitHub Profile
@finalwebsites
finalwebsites / functions.php
Created November 5, 2023 13:48
Set image ALT Tag after upload via the WordPress media library
View functions.php
<?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 / hide_coupons.php
Created October 20, 2023 14:14
Disable the coupon form on the checkout page from WooCommerce
View hide_coupons.php
<?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
View Elementor_Form_to_EmailOctopus_API.php
<?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 / wordpress-faq-shortcode.php
Last active October 20, 2023 18:38
WordPress FAQ shortcode with stucutured data notations
View wordpress-faq-shortcode.php
<?php
function fws_create_faq_list($atts) {
$atts = shortcode_atts(
array(
'soort' => ''
),
$atts
);
$html = '';
@finalwebsites
finalwebsites / wc-replace-add-to-cart-btn.php
Created September 29, 2023 12:27
WordPress hooks add-to-cart button replacement
View wc-replace-add-to-cart-btn.php
<?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>';
}
@finalwebsites
finalwebsites / wc-product-tabs.php
Created September 29, 2023 12:19
WordPress hooks for the WooCommerce product detail page
View wc-product-tabs.php
<?php
// verwijder (dubbele) headings
add_filter( 'woocommerce_product_description_heading', '__return_null' );
// verwijder het tabje met de extra informatie
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 99 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['additional_information'] );
return $tabs;
}
@finalwebsites
finalwebsites / shortcode_image_tag.php
Last active September 1, 2023 10:51
Add the shortcode option to dynamic tags for background images in Elementor
View shortcode_image_tag.php
<?php
// place the snippet inside the functions.php file from your WordPress child theme
use Elementor\Controls_Manager;
add_action( 'elementor/dynamic_tags/register_tags', function( $dynamic_tags ) {
class Custom_Image_Tag extends Elementor\Core\DynamicTags\Data_Tag {
public function get_name() {
return 'shortcode-image';
}
@finalwebsites
finalwebsites / bedankpagina.php
Created April 20, 2023 18:15
WooCommerce: Redirect the customer to your own thank you page (one for successful payments and one for all other statuses)
View bedankpagina.php
<?php
add_action( 'woocommerce_thankyou', 'fw_redirect_custom_thank_you_page');
function fw_redirect_custom_thank_you_page( $order_id ){
$order = wc_get_order( $order_id );
$url = home_url('/YOUR_THANK_YOU_PAGE/'); // <<< change this slug
if ( $order->has_status( array('processing', 'completed' ) ) ) {
wp_safe_redirect( $url );
exit;
}
}
@finalwebsites
finalwebsites / functions.php
Created April 16, 2023 13:18
Child theme for WordPress
View functions.php
<?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 / woocommerce_archive_description.php
Last active April 15, 2023 14:25
WooCommerce hooks example codes
View woocommerce_archive_description.php
<?php
// remove the category description above the product list
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
// add the category description below the product list
add_action( 'woocommerce_after_shop_loop', 'woocommerce_taxonomy_archive_description', 100 );