Skip to content

Instantly share code, notes, and snippets.

View woogist's full-sized avatar

WooCommerce.com Documentation woogist

View GitHub Profile
// Adjust Date Column Output
function wc_csv_export_format_data( $order_data ) {
for( $i = 0; $i < count( $order_data ); $i++ ) {
if ( isset( $order_data[ $i ]['order_date'] ) ) {
$order_data[ $i ]['order_date'] = date_i18n( 'd/m/Y', strtotime( $order_data[ $i ]['order_date'] ) );
}
}
return $order_data;
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );
function is_product_eligible( $eligible, $product, $discounter_name, $discounter_object ) {
remove_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );
if ( $product->is_on_sale() ) {
$eligible = false;
}
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );
function wc_edit_bookings_form_fields_order( $fields ) {
$duration = $fields['wc_bookings_field_duration'];
$persons = $fields['wc_bookings_field_persons'];
$resource = $fields['wc_bookings_field_resource'];
$date = $fields['wc_bookings_field_start_date'];
$new_fields = array(
'wc_bookings_field_start_date' => $date,
'wc_bookings_field_resource' => $resource,
'wc_bookings_field_duration' => $duration,
wc_enqueue_js( "
jQuery( '.add_to_cart_inline .qty' ).on( 'change', function() {
var qty = jQuery( this ),
atc = jQuery( this ).next( '.add_to_cart_button' );
atc.attr( 'data-quantity', qty.val() );
});
" );
if ( ! is_shop() && ! is_product_taxonomy() ) {
$quantity_field = woocommerce_quantity_input( array(
'input_name' => 'product_id',
'input_value' => ! empty( $product->cart_item['quantity'] ) ? $product->cart_item['quantity'] : 0,
'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity(),
'min_value' => 0,
), $product, false );
$quantity_field = str_replace( array( '<div class="quantity">', "</div>" ), '', $quantity_field );
echo str_replace( '<input ', '<input style="max-width: 70px" ', $quantity_field );
/**
* Hides the Ninja Forms add-ons' prices in the cart and checkout pages
*
* @param string $text
* @return string
*/
function wc_nf_hide_price( $text ) {
$text = strip_tags( $text ); // Strip HTML tags <span class="amount"></span>
$pattern = "/\s\((\D{0,2}\d{0,3};)\s?\d+([\.,]\d+)?\s?[\D+]?\)$/";
add_action( 'manage_wc_booking_posts_custom_column', 'wc_custom_bookings_columns', 3 );
function wc_custom_bookings_columns( $column ) {
global $post, $booking;
if ( empty( $booking ) || $booking->id != $post->ID ) {
$booking = get_wc_booking( $post->ID );
}
switch ( $column ) {
case 'customer':
@woogist
woogist / functions.php
Created April 30, 2015 12:01
display the customer login name in Bookings > All Bookings
add_action( 'manage_wc_booking_posts_custom_column', 'wc_custom_bookings_columns', 3 );
function wc_custom_bookings_columns( $column ) {
global $post, $booking;
if ( empty( $booking ) || $booking->id != $post->ID ) {
$booking = get_wc_booking( $post->ID );
}
switch ( $column ) {
case 'customer':
@woogist
woogist / functions.php
Created April 23, 2015 10:34
Move the attributes outside the tabs
add_action( 'woocommerce_single_product_summary', 'wc_custom_show_attributes_outside_tabs', 35 );
function wc_custom_show_attributes_outside_tabs() {
global $product;
$product->list_attributes();
}
@woogist
woogist / product-searchform.php
Created April 13, 2015 07:30
product-searchform.php
<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>