This file contains 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
// 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 ){ | |
if($filter_id == 601){ | |
asort($options); |
This file contains 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
// 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="leoclean-price-suffix">Preis inkl. MwSt. & exkl. Versand</span>'; | |
} | |
return apply_filters( 'woocommerce_get_price', $price ); | |
} |
This file contains 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
// Add Back to Shop button on Single Product Template | |
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>'; | |
} |
This file contains 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
// Replace the Add to Cart Button on Single Product Template to go to a link that is decided by an ACF plugin 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 | |
echo '<a class="button" style="text-align: center; margin-bottom: 10px;" target="_blank" href="'.get_field('external_product_link', $product->get_id()).'">' . $button_text . '</a>'; | |
} |
This file contains 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
// 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", "the7dt-child"); | |
$button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>'; | |
return $button; | |
} |
This file contains 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
// 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); |
This file contains 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_shortcode('check_if_scraper_plugin_is_active', function() { | |
if(is_plugin_active('product-scraper/product-scraper.php')) { | |
return true; | |
} else { | |
return false; | |
} | |
}); |
This file contains 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 | |
// 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; | |
} |
This file contains 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 | |
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') { | |
?> |
This file contains 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
// Remove product count from category listing | |
add_filter( 'woocommerce_subcategory_count_html', '__return_false' ); |
NewerOlder