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
Last active January 12, 2024 08:10
Woocommerce Update the product skus with the number that is gathered from the Product Title. SKU is in parentheses
// 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
);
$products = get_posts($args);
@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;
}
@emre-edu-tech
emre-edu-tech / functions.php
Created November 21, 2023 09:43
Wocoommerce - Detect user Country on Checkout Page
<?php
function get_user_geo_country(){
if(is_checkout()) {
$geo = new WC_Geolocation(); // Get WC_Geolocation instance object
$user_ip = $geo->get_ip_address(); // Get user IP
$user_geo = $geo->geolocate_ip( $user_ip ); // Get geolocated user data.
$country = $user_geo['country']; // Get the country code
if($country != 'DE') {
?>
@emre-edu-tech
emre-edu-tech / functions.php
Created November 21, 2023 09:31
Various Woocommerce Filters about Products and Categories
// Remove product count from category listing
add_filter( 'woocommerce_subcategory_count_html', '__return_false' );
@emre-edu-tech
emre-edu-tech / functions.php
Last active November 21, 2023 09:23
Show quantity and quantity buttons next to Add to Cart buttons on Woocommerce Product Archive Template
<?php
/**
* Override loop template and show quantity and quantity buttons next to add to cart buttons
*/
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input( array(), $product, false );
@emre-edu-tech
emre-edu-tech / functions.php
Last active December 5, 2023 17:39
Shortcode to check if a plugin is active. In this example, a plugin with the directory name and main plugin file is used.
<?php
add_shortcode('check_if_scraper_plugin_is_active', function() {
if(is_plugin_active('product-scraper/product-scraper.php')) {
return true;
} else {
return false;
}
});
@emre-edu-tech
emre-edu-tech / functions.php
Created May 5, 2023 08:20
how to make a ACF field readonly.
// Make Custom Field Readonly
function make_price_field_readonly($field) {
$field['readonly'] = true;
return $field;
}
add_filter('acf/prepare_field/name=price_field_name', 'make_price_field_readonly');
@emre-edu-tech
emre-edu-tech / functions.php
Created April 28, 2023 10:19
Woocommerce - Remove the tab titles on Single Product Template
// REMOVE TAB TITLES ON SINGLE PRODUCT TEMPLATE
// Remove Description Title from Single Product Page Tabs
add_filter('woocommerce_product_description_heading', '__return_null');
// Remove Additional Information Title from Single Product Page Tabs
add_filter('woocommerce_product_additional_information_heading', '__return_null');
// Remove Reviews Title from Single Product Page Tabs
add_filter('woocommerce_reviews_title', '__return_null');
@emre-edu-tech
emre-edu-tech / wp-recommended-font-sizes.txt
Last active April 13, 2023 10:05
Wordpess Recommended Font Sizes
@emre-edu-tech
emre-edu-tech / theme.json
Last active April 14, 2023 07:29
Wordpress Full Site Editor theme.json sample file with a Visual Studio Code Schema - Theme Prefix is devforwp
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"typography": {
"fontFamilies": [
{ "fontFamily": "Rubik, sans-serif", "slug": "devforwp-rubik", "name": "DevForWp Rubik" }
],
"fontSizes": [
{ "slug": "small", "size": "0.75rem", "name": "Small" },