Skip to content

Instantly share code, notes, and snippets.

View jswebschmiede's full-sized avatar
🏠
Working from home

Joerg Schoeneburg jswebschmiede

🏠
Working from home
View GitHub Profile
@jswebschmiede
jswebschmiede / image-src-regexpr.php
Created March 23, 2023 15:46 — forked from vyspiansky/image-src-regexpr.php
PHP: get image src attribute (regular expression)
<?php
// Source: http://goo.gl/qyLFbg
$html = '<img border="0" src="/images/image.jpg" alt="Image" width="100" height="100" />';
preg_match( '@src="([^"]+)"@' , $html, $match );
$src = array_pop($match);
// will return /images/image.jpg
@jswebschmiede
jswebschmiede / scrollTo.js
Created February 2, 2023 14:37 — forked from frob/scrollTo.js
a native scrollTo function in javascript that uses requestAnimationFrame and easing for animation
// easing functions http://goo.gl/5HLl8
Math.easeInOutQuad = function (t, b, c, d) {
t /= d/2;
if (t < 1) {
return c/2*t*t + b
}
t--;
return -c/2 * (t*(t-2) - 1) + b;
};
@jswebschmiede
jswebschmiede / woocommerce - minimum and maximum price
Created April 20, 2022 15:13 — forked from Daniel217D/woocommerce - minimum and maximum price
woocommerce - get minimum and maximum price for current products
function get_filtered_price() {
global $wpdb;
$args = wc()->query->get_main_query();
$tax_query = isset( $args->tax_query->queries ) ? $args->tax_query->queries : array();
$meta_query = isset( $args->query_vars['meta_query'] ) ? $args->query_vars['meta_query'] : array();
foreach ( $meta_query + $tax_query as $key => $query ) {
if ( ! empty( $query['price_filter'] ) || ! empty( $query['rating_filter'] ) ) {
@jswebschmiede
jswebschmiede / wc-change-number-of-related-products.php
Created April 20, 2022 10:33 — forked from woogists/wc-change-number-of-related-products.php
[Theming Snippets] Change number of related products output
@jswebschmiede
jswebschmiede / wc-product-search-form.html
Created April 20, 2022 10:33 — forked from woogists/wc-product-search-form.html
[Theming] Overriding the product search box (widget)
<form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'woocommerce' ); ?></label>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Products&hellip;', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'woocommerce' ); ?>" />
<input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" />
<input type="hidden" name="post_type" value="product" />
</form>
@jswebschmiede
jswebschmiede / wc-query-woocommerce-active.php
Created April 20, 2022 10:29 — forked from woogists/wc-query-woocommerce-active.php
[Theming Snippets] Query whether WooCommerce is activated
/**
* Check if WooCommerce is activated
*/
if ( ! function_exists( 'is_woocommerce_activated' ) ) {
function is_woocommerce_activated() {
if ( class_exists( 'woocommerce' ) ) { return true; } else { return false; }
}
}
@jswebschmiede
jswebschmiede / hide-all-shipping-keep-local-free.php
Created April 20, 2022 10:28 — forked from woogists/hide-all-shipping-keep-local-free.php
[General Snippets][Hide other shipping methods, but keep "Local pickup" when “Free Shipping” is available]
/**
* Hide shipping rates when free shipping is available, but keep "Local pickup"
* Updated to support WooCommerce 2.6 Shipping Zones
*/
function hide_shipping_when_free_is_available( $rates, $package ) {
$new_rates = array();
foreach ( $rates as $rate_id => $rate ) {
// Only modify rates if free_shipping is present.
if ( 'free_shipping' === $rate->method_id ) {
@jswebschmiede
jswebschmiede / wc-hide-all-shipping-if-free-shipping-is-available.php
Created April 20, 2022 10:27 — forked from woogists/wc-hide-all-shipping-if-free-shipping-is-available.php
[General Snippets][Hide other shipping methods when “Free Shipping” is available] Hides all other shipping methods but free_shipping if it’s available. Compatible with Shipping zones.
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
@jswebschmiede
jswebschmiede / hide-shipping-if-free-shipping-is-available.php
Created April 20, 2022 09:54 — forked from JeroenSormani/hide-shipping-if-free-shipping-is-available.php
New - Hide paid shipping rates when free is available. DOES show Local Pickup. Considered ANY shipping rate that is $0 as free (so the 'Free shipping' shipping method is not a requirement)
<?php
/**
* Copy from here to your (child) themes functions.php
* Recommended to do so via FTP.
*/
/**
* Hide all but the free shipping options when free is available.
*
@jswebschmiede
jswebschmiede / wp-coustom-term-options.php
Created April 19, 2022 22:21 — forked from svebal/wp-coustom-term-options.php
Wordpress Hooks to add coustom term Options
<?php
/**
*
* Add only for parents coustom term Options
* @author rene reimann
* @home http://www.rene-reimann.de
*
* @hook category_add_form_fields Hooks into the category edit page
* @hook edit_tag_form_fields Hooks into the category frontpage