This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('woocommerce_after_shop_loop_item_title', 'add_custom_product_info', 18); | |
function add_custom_product_info() { | |
global $product; | |
$product_unit_price = get_field('unit_price', $product->id); | |
// Displaying the custom field only when is set with a value | |
if(!empty($product_unit_price )) { | |
// Change text-domain with your own. | |
echo '<p style="color: red; font-weight: 600; font-size: 1.2rem">' . __('Ab ', 'text-domain') . $product_unit_price . '€ / Stück</p>'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 ); | |
function shorten_woo_product_title( $title, $id ) { | |
if (!is_singular(array('product')) && get_post_type($id) === 'product') { | |
// return substr( $title, 0, 30) . '…'; // change last number to the number of characters you want | |
return wp_trim_words($title, 4); // last number = words | |
} else { | |
return $title; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// creating custom woocommerce order by an acf field called custom_product_popularity | |
function leoshop_add_new_postmeta_orderby( $sortby ) { | |
$sortby['custom_popularity'] = __( 'Sortieren nach benutzerdefinierten', 'hello-theme-child'); | |
return $sortby; | |
} | |
add_filter( 'woocommerce_default_catalog_orderby_options', 'leoshop_add_new_postmeta_orderby' ); | |
add_filter( 'woocommerce_catalog_orderby', 'leoshop_add_new_postmeta_orderby' ); | |
function leoshop_add_postmeta_ordering_args( $sort_args ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// [leoshop_get_products_by_category_id category_id='87' property='cleaning'] | |
add_shortcode('leoshop_get_products_by_category_id', 'leoshop_get_products_by_category_id'); | |
function leoshop_get_products_by_category_id($attr) { | |
// get the attributes of shortcode | |
$args = shortcode_atts([ | |
'category_id' => 87, | |
'property' => 'cat_name', | |
], $attr ); | |
$term = get_term($args['category_id'], 'product_cat'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Theme Name: Media Pons (Required) | |
Theme URI: https://media-pons.de/mediapons-base-theme/ (Optional) | |
Author: Media Pons (Optional) | |
Author URI: https://media-pons.de/ (Optional) | |
Description: Custom theme that is a base theme for developing example WordPress themes. This base theme uses Tailwindcss. (Optional) | |
Version: 1.0.0 (Optional) | |
License: GPLv2 or later | |
License URI: https://www.gnu.org/licenses/gpl-2.0.html (Optional) | |
Text Domain: media-pons (Optional - it should match the theme folder name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Here we use tax query but meta_query is also possible | |
// Unfortunately, there is no way to merge Wordpress default search behaviour, meta_query and tax_query using OR | |
// that I could find. | |
// Default behaviour for merging these queries are AND. | |
// Custom Elementor Query for Search | |
function mpons_custom_property_search_query($query) { | |
// Get the search term from the WP_Query object | |
$search_term = $query->get('s'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package MPonsCustomPlugin | |
*/ | |
/* | |
Plugin Name: MPons Custom Plugin | |
Plugin URI: https://mediapons.de | |
Description: This is an example plugin to practice WordPress Plugin Development. | |
Version: 1.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* ABSPATH is a constant in WordPress that stores the absolute path to the WordPress installation directory on the server. | |
* It is defined in the core wp-config.php file like this: | |
*/ | |
define('ABSPATH', dirname(__FILE__) . '/'); | |
/* | |
* PURPOSE OF THE ABSPATH CHECK | |
* This check below guarantees that no one from outside of the WordPress installation should access this file directly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Check if GD is installed | |
if (!extension_loaded('gd')) { | |
die("GD library is not installed. Please enable it in your PHP configuration."); | |
} | |
// Set image dimensions and properties | |
$width = 1200; | |
$height = 900; | |
$backgroundColor = [240, 240, 240]; // Light gray background |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Show price suffix just on single product template but not on related products section | |
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 10, 2 ); | |
function custom_price_suffix( $price, $product ) { | |
global $woocommerce_loop; | |
if(is_product() && ($woocommerce_loop['name'] != 'related')) { | |
$price = $price . ' <span class="leoshop-price-suffix"> Preis inkl. MwSt. & exkl. Versand</span>'; | |
} | |
return $price; | |
} |
NewerOlder