Skip to content

Instantly share code, notes, and snippets.

View SiR-DanieL's full-sized avatar

Nicola Mustone SiR-DanieL

View GitHub Profile
@SiR-DanieL
SiR-DanieL / base64 sh.txt
Last active August 29, 2015 13:56
Generate crypted passwords in base64
/bin/echo "{md5}"`/bin/echo -n "password" | openssl dgst -binary -md5 | openssl enc -base64`
add_action( 'woocommerce_product_thumbnails'. 'your_custom_function' );
function your_custom_function() {
?>
<img src="http://domain.com/image.jpg" title="Your title" alt="Your alt" />
<?php
}
@SiR-DanieL
SiR-DanieL / gist:3659c323e25d50d135c7
Last active August 29, 2015 14:06
Add checkout VAT and SSN fields
// Add VAT and SSN fields to the checkout form
add_filter( 'woocommerce_checkout_fields' , 'custom_add_vat_ssn_fields' );
function custom_add_vat_ssn_fields( $fields ) {
if ( ! isset( $fields['billing']['billing_vat'] ) ) {
$fields['billing']['billing_vat'] = array(
'label' => __( 'VAT', 'your-domain' ),
'placeholder' => _x( 'VAT', 'placeholder', 'your-domain' ),
'required' => true, //change to false if you do not need this field to be required
'class' => array( 'form-row-first' )
);
@SiR-DanieL
SiR-DanieL / gist:b87314a6267b45c41302
Created September 29, 2014 07:37
add woocommerce customer vat and ssn fields
add_filter( 'woocommerce_my_account_my_address_formatted_address', 'custom_my_account_my_address_formatted_address', 10, 3 );
function custom_my_account_my_address_formatted_address( $fields, $customer_id, $type ) {
if ( $type == 'billing' ) {
$fields['vat'] = get_user_meta( $customer_id, 'billing_vat', true );
$fields['ssn'] = get_user_meta( $customer_id, 'billing_ssn', true );
}
return $fields;
}
@SiR-DanieL
SiR-DanieL / gist:21899c057aad33fd9fdd
Last active August 29, 2015 14:07
add woocommerce admin order vat and ssn fields
// Add VAT and SSN fields in billing address display
add_filter( 'woocommerce_order_formatted_billing_address', 'custom_add_vat_ssn_formatted_billing_address', 10, 2 );
function custom_add_vat_ssn_formatted_billing_address( $fields, $order ) {
$fields['vat'] = $order->billing_vat;
$fields['ssn'] = $order->billing_ssn;
return $fields;
}
add_filter( 'woocommerce_admin_billing_fields', 'custom_admin_billing_fields' );
@SiR-DanieL
SiR-DanieL / gist:896fd11690b7d6597460
Last active August 29, 2015 14:07
woocommerce load JS file for admin order page async loading
add_action( 'admin_enqueue_scripts', 'enqueue_custom_wc_load_address_js' );
function enqueue_custom_wc_load_address_js() {
wp_enqueue_script( 'custom-wc-load-address', untrailingslashit( get_template_directory_uri() ) . '/jquery.wc-custom.js', array( 'wc-admin-order-meta-boxes' ) );
}
if ( is_numeric( $download['downloads_remaining'] ) )
echo apply_filters( 'woocommerce_available_download_count', '' . sprintf( _n( '%s download remaining', '%s downloads remaining', $download['downloads_remaining'], 'woocommerce' ), $download['downloads_remaining'] ) . ' ', $download );
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
$order_id = absint( $wp->query_vars['order-received'] );
wp_redirect( get_permalink( {PAGE_ID} ) . '?order=' . $order_id );
exit;
}
}
$product_tags = wp_get_post_terms( $product->id, 'product_tag' );
if ( ! empty( $product_tags ) ) {
foreach( $product_tags as $tag ) {
if ( $tag->slug === 'tag-slug' && ! is_user_logged_in() ) {
return;
}
}
}
/**
* Add the meta _transaction_id in the search fields.
*
* @param array $fields
* @return array
*/
function wc_custom_order_filter_fields( $fields ) {
if ( ! in_array( '_transaction_id', $fields ) ) {
array_push( $fields, '_transaction_id' );
}