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 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
Last active October 13, 2024 07:14
Filter to remove the product count from the list of categories
<?php
// 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
Last active October 13, 2024 06:06
Making an ACF field readonly to prevent the users to enter a value.
<?php
// Make Custom Field Readonly
function make_price_field_readonly($field) {
$field['readonly'] = true;
return $field;
}
// price_field_name is the slug of the Custom Field
add_filter('acf/prepare_field/name=price_field_name', 'make_price_field_readonly');
@emre-edu-tech
emre-edu-tech / functions.php
Last active October 13, 2024 06:07
Woocommerce - Remove the tab titles on Single Product Template
<?php
// 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 / theme.json
Last active November 15, 2024 12:25
Wordpress Full Site Editor theme.json sample file with a Visual Studio Code Schema - Theme Prefix is mpons
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"typography": {
"fontFamilies": [
{ "fontFamily": "Rubik, sans-serif", "slug": "mpons-rubik", "name": "Mpons Rubik" }
],
"fontSizes": [
{ "slug": "small", "size": "0.75rem", "name": "Small" },
@emre-edu-tech
emre-edu-tech / functions.php
Last active October 13, 2024 07:17
Woocommerce - Change add to cart button to a Product Details Button on product archive page
<?php
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_add_to_cart_button_on_product_archive', 10, 2 );
function replace_add_to_cart_button_on_product_archive($button, $product) {
$button_text = __("Show Product", "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:21
This is a demonstration of how to add different favicons manually in custom wordpress theme using functions.php
<?php
//It is not super complete but it is ok for the start
// Remember that $favicon_path will change according to your assets directory structure
function add_favicons() {
// declare the path variables
$favicon_path = get_template_directory_uri() . '/assets/img/favicon.ico';
$apple_touch_icon_72x72_path = get_template_directory_uri() . '/assets/img/apple-touch-icon-72x72.png';
$apple_touch_icon_114x114_path = get_template_directory_uri() . '/assets/img/apple-touch-icon-114x114.png';
// echo to the wp_head anchor to append to it
@emre-edu-tech
emre-edu-tech / functions.php
Last active September 24, 2020 09:52
This is a Custom Wordpress Nav Walker implementation for a custom Bootstrap Menu.
<?php
// So-called menu is below and we will implement this custom menu by extending Walker_Nav_Menu class
/*
<ul>
<li class="active"><a href="index.html">Home</a></li>
<li class="drop-down"><a href="">About</a>
<ul>
<li><a href="about.html">About Us</a></li>
<li><a href="team.html">Team</a></li>
<li><a href="testimonials.html">Testimonials</a></li>