Skip to content

Instantly share code, notes, and snippets.

@sejas
Last active February 12, 2026 23:35
Show Gist options
  • Select an option

  • Save sejas/291e1d0a1157eefb724b6d73fd414da1 to your computer and use it in GitHub Desktop.

Select an option

Save sejas/291e1d0a1157eefb724b6d73fd414da1 to your computer and use it in GitHub Desktop.
WordPress & WooCommerce Snippets (Collection)

WordPress & WooCommerce Snippets

Modify oEmbed WordPress YouTube video parameters

filter to modify oembed wordpress youtube video parameters

<?php
//If you have installed jetpack, you need to add this filter.

/* $html example value:
<span class="embed-youtube" style="text-align:center; display: block;"><iframe class='youtube-player' type='text/html' width='1220' height='717' src='http://www.youtube.com/embed/ZuYCXwcCNqM?version=3&#038;rel=1&#038;fs=1&#038;autohide=2&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' allowfullscreen='true' style='border:0;'></iframe></span>
*/
function bau_video_embed_html( $html ) {
	if(strpos($html, 'youtube')!= FALSE) {
		$args = [
			'rel' => 0,
			'controls' => 0,
			'showinfo' => 0,
			'modestbranding' => 1,
		];
		$params = '?version=3&#038;';
		foreach($args as $arg => $value){
			$params .= $arg;
			$params .= '=';
			$params .= $value;
			$params .= '&#038;';
		}
		$result = str_replace( '?version=3', $params, $html );
	}
	return $result;
}
add_filter('video_embed_html', 'bau_video_embed_html', 10, 3);

Free shipping to Europe 150+ WooCommerce

free shipping to europe 150+ woocommerce

array(
	array(
			672037005 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037010 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "AT"	
			)	
	),
	array(
			672037015 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037020 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "BE"	
			)	
	),
	array(
			672037025 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037030 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "BG"	
			)	
	),
	array(
			672037035 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037040 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "CY"	
			)	
	),
	array(
			672037045 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037050 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "CZ"	
			)	
	),
	array(
			672037055 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037060 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "DK"	
			)	
	),
	array(
			672037065 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037070 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "EE"	
			)	
	),
	array(
			672037075 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037080 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "FI"	
			)	
	),
	array(
			672037085 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037090 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "FR"	
			)	
	),
	array(
			672037095 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037100 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "DE"	
			)	
	),
	array(
			672037105 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037110 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "GR"	
			)	
	),
	array(
			672037115 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037120 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "HU"	
			)	
	),
	array(
			672037125 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037130 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "IE"	
			)	
	),
	array(
			672037135 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037140 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "IT"	
			)	
	),
	array(
			672037145 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037150 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "LV"	
			)	
	),
	array(
			672037155 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037160 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "LT"	
			)	
	),
	array(
			672037165 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037170 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "LU"	
			)	
	),
	array(
			672037175 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037180 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "MT"	
			)	
	),
	array(
			672037185 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037190 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "NL"	
			)	
	),
	array(
			672037195 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037200 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "PL"	
			)	
	),
	array(
			672037205 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037210 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "PT"	
			)	
	),
	array(
			672037215 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037220 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "RO"	
			)	
	),
	array(
			672037225 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037230 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "SK"	
			)	
	),
	array(
			672037235 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037240 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "SI"	
			)	
	),
	array(
			672037245 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037250 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "ES"	
			)	
	),
	array(
			672037255 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037260 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "SE"	
			)	
	),
	array(
			672037265 => array(
				"condition" => "subtotal",
		        "operator" => ">=",
		        "value" => "150"
			),
			672037270 => array(
				"condition" => "country",
		        "operator" => "==",
		        "value" => "GB"	
			)	
	),

)

WooCommerce - Add checkbox field to checkout

WooCommerce - Add checkbox field to the checkout

<?php

/**
 * Add checkbox field to the checkout
 **/

$myCheckboxKey = 'my_checkbox';

add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
 
    echo '<div id="my-new-field"><h3>'.__('My Checkbox: ').'</h3>';
 
    woocommerce_form_field( $myCheckboxKey, array(
        'type'          => 'checkbox',
        'class'         => array('input-checkbox'),
        'label'         => __('I have read and agreed.'),
        'required'  => true,
        ), $checkout->get_value( $myCheckboxKey ));
 
    echo '</div>';
}
 
/**
 * Process the checkout
 **/
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
 
function my_custom_checkout_field_process() {
    // Check if set, if its not set add an error.
    if (!$_POST[$myCheckboxKey])
        wc_add_notice( __('Please agree to my checkbox.'), 'error' );
}
 
/**
 * Update the order meta with field value
 **/
add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');
 
function my_custom_checkout_field_update_order_meta( $order_id ) {
    if ($_POST[$myCheckboxKey]) update_post_meta( $order_id, $myCheckboxKey, esc_attr($_POST[$myCheckboxKey]));
}

?>

Remove password strength meter from WooCommerce checkout

Remove the password strength meter from WooCommerce checkout

function wc_ninja_remove_password_strength() {
	if ( wp_script_is( 'wc-password-strength-meter', 'enqueued' ) ) {
		wp_dequeue_script( 'wc-password-strength-meter' );
	}
}
add_action( 'wp_print_scripts', 'wc_ninja_remove_password_strength', 100 );

Add new tabs with Advanced Custom Fields content

Add new tabs with the content of Advanced Custom Fields.

<?php
/**
 * Add new tabs with the content of Advanced Custom Fields.
 */
add_filter( 'woocommerce_product_tabs', 'bau_woo_remove_product_tabs', 98 );
function bau_woo_remove_product_tabs( $tabs ) {
    // Define, the meta_key of the 
    $bautabs = array(
        'alergenos' => array(
                'title' => __('Alérgenos'),
            )
        ,'preparacion' => array(
                'title' => __('Preparación')
            )
        );

    foreach ($bautabs as $bau_meta_key => $bauTab) {
    $tabContent = get_post_meta( get_the_ID(), $bau_meta_key, true );
    if ($tabContent && "" != $tabContent && null != $tabContent) {
        $tabs[$bau_meta_key] = array(
          'title' => $bauTab['title'],
          'priority' => (isset($bauTab['priority']))?$bauTab['priority']:21,
          'tabContent' => $tabContent,
          'callback' => function ($tabName,$tab)
          {
            echo wpautop($tab['tabContent']);
          },
        );   
     }   
    }
    return $tabs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment