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 December 5, 2024 15:37
This shortcode creates a custom woocommerce order type by an acf field called custom_product_popularity.
<?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 ) {
@emre-edu-tech
emre-edu-tech / functions.php
Created December 7, 2024 08:31
Filter to limit or trim product title using characters or words except on Single Product Template
<?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;
}
}
@emre-edu-tech
emre-edu-tech / functions.php
Created December 7, 2024 09:36
Add an ACF field after shop item title on Shop or Product Category page template
<?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>';
}