Skip to content

Instantly share code, notes, and snippets.

View SiR-DanieL's full-sized avatar

Nicola Mustone SiR-DanieL

View GitHub Profile
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' );
}
/**
* Hides checkout fields based on the products in the cart
*
* @param array $fields
* @return array
*/
function conditional_checkout_fields_products( $fields ) {
$cart = WC()->cart->get_cart();
$has_tag = true;
// Enable WP_DEBUG mode
define('WP_DEBUG', true);
// Enable Debug logging to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);
function customize_grouped_product_title( $tilte, $product ) {
if ( $product->get_parent() > 0 ) {
$title = get_the_title( $product->id );
}
return $title;
}
function temporary_fix_product_search( $where ) {
global $pagenow, $wpdb, $wp;
if ( 'edit.php' != $pagenow || ! is_search() || ! isset( $wp->query_vars['s'] ) || 'product' != $wp->query_vars['post_type'] ) {
return $where;
}
$where = str_replace( "post_type = ' '", "post_type = 'product'", $where );
return $where;
}
@SiR-DanieL
SiR-DanieL / functions.php
Created September 4, 2015 06:05
Show hidden products on the OPC page.
add_filter( 'wcopc_products_query_args', 'wc_opc_show_hidden_products' );
function wc_opc_show_hidden_products( $args ) {
if ( isset( $args['meta_query'] ) ) {
array_push( $args['meta_query'][0]['value'], 'hidden' );
}
return $args;
}
add_filter( 'woocommerce_product_thumbnails_columns', create_function( '', 'return 4;' ) );
@SiR-DanieL
SiR-DanieL / functions.php
Created September 8, 2015 08:09
Increase the variations threshold to 50
add_filter( 'woocommerce_ajax_variation_threshold', 'wc_ninja_ajax_threshold' );
function wc_ninja_ajax_threshold() {
return 50;
}