Skip to content

Instantly share code, notes, and snippets.

View emre-edu-tech's full-sized avatar

Media Pons emre-edu-tech

View GitHub Profile
@emre-edu-tech
emre-edu-tech / functions.php
Created August 19, 2024 14:09
This filter is used with All In One WP Migration plugin to exclude the stated folders from the export.
<?php
add_filter('ai1wm_exclude_content_from_export', function($exclude_filters) {
$exclude_filters[] = 'themes/your-theme-name';
return $exclude_filters;
});
@emre-edu-tech
emre-edu-tech / functions.php
Created August 13, 2024 08:36
Elementor Pro Form Prepopulate Select Field in two forms (One on a page and one on a popup)
<?php
// render elementor forms select item for year_built in Angebotsanfrage form
// rerender the select field using elementor form api
add_filter('elementor_pro/forms/render/item/select', function($item, $index, $form) {
if('vehicle_quote_form' === $form->get_settings_for_display('form_name') || 'vehicle_quote_form_popup' === $form->get_settings_for_display('form_name')) {
if('year_built' == $item['custom_id'] || 'year_built_popup' == $item['custom_id']) {
$item['field_options'] = "Bitte Jahr auswählen|\n";
for($year=date('Y'); $year >= 1970; $year--) {
if($year != 1970) {
$item['field_options'] .= $year . "|" . $year . "\n";
@emre-edu-tech
emre-edu-tech / functions.php
Last active October 13, 2024 06:08
Checking the custom post type mapped capabilities while in development stage.
<?php
// FOR DEVELOPMENT PURPOSES, create a submenu page that displays the capabilities of
// Custom Post Type which is called Topic and this page is only available to ADMINS
add_action('admin_menu', 'mpons_forum_submenu');
function mpons_forum_submenu() {
add_submenu_page(
'tools.php',
__('Media Pons Topic CPT', 'media-pons-forum'),
__('Media Pons Topic CPT', 'media-pons-forum'),
@emre-edu-tech
emre-edu-tech / functions.php
Last active October 13, 2024 06:51
Various code snippets for Crocoblock Plugins
<?php
// Crocoblock Code Snippets
// Jet Smart Filters
// -----------------
// Snippet No: 1
// This code below sorts an array of filters that are related to a Custom Post Type
// Because Custom Post Type values are not coming in alphabetical order, this code is needed
// 601 is the Id of Jet Smart Filter Type
function theme_name_jet_filter_options( $options, $filter_id, $filter ){
@emre-edu-tech
emre-edu-tech / functions.php
Last active October 13, 2024 07:08
Update the price suffix using woocommerce_get_price_html filter and show it only on Single Product Template
<?php
// Show price suffix only on single product page
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );
function custom_price_suffix( $price, $product ) {
if(is_singular('product')) {
$price = $price . ' <span class="mpons-price-suffix">Preis inkl. MwSt. & exkl. Versand</span>';
}
return apply_filters( 'woocommerce_get_price', $price );
}
@emre-edu-tech
emre-edu-tech / functions.php
Last active October 13, 2024 06:54
Code snippet that adds Back to Products/Shop button on Single Product Template
<?php
// Add "Back to Shop" button on Single Product Template
// Sometimes it is useful a button to get back to Shop page
add_action('woocommerce_before_single_product', 'print_back_to_products_btn');
function print_back_to_products_btn() {
$shop_page_url = get_permalink(woocommerce_get_page_id( 'shop' ));
echo '<a style="margin-bottom: 10px" class="button" href="' . $shop_page_url . '"><i class="fas fa-arrow-left"></i> All Products</a>';
}
<?php
// Replace the Add to Cart Button on Single Product Template to go to a link that is also an ACF plugin URL field
add_action( 'woocommerce_single_product_summary', 'replace_single_add_to_cart_button', 1 );
function custom_product_button(){
$product = wc_get_product();
// HERE your custom button text and link
$button_text = __( "Buy from external resource", "custom-textdomain" );
// Display button
@emre-edu-tech
emre-edu-tech / functions.php
Last active October 13, 2024 07:03
Change add to cart button to custom button on Product Archive Page
<?php
// Wooconmmerce - Change add to cart button to custom button on product archive page
add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
function replacing_add_to_cart_button( $button, $product ) {
$button_text = __("Produkt Details", "textdomain");
$button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
return $button;
}
@emre-edu-tech
emre-edu-tech / functions.php
Last active October 13, 2024 07:10
Woocommerce Update the product skus with the number that is gathered from the Product Title. In this example SKU is in parentheses in Product Title.
<?php
// Update the product skus with the number that is gathered from the Product Title. SKU is in parentheses
// Make it available as an admin page
function update_product_skus() {
$args = array(
'post_type' => 'product',
'posts_per_page' => -1, // Retrieve all products; adjust if needed
);
@emre-edu-tech
emre-edu-tech / functions.php
Created November 21, 2023 09:49
Wordpress - Tweak the logout function. Redirect user to home page after logging out.
<?php
// Tweak the logout function to redirect to home page after logging out
add_action('wp_logout','auto_redirect_after_logout');
function auto_redirect_after_logout(){
wp_safe_redirect( home_url() );
exit;
}