Skip to content

Instantly share code, notes, and snippets.

View wbcomdev's full-sized avatar

Wbcom Dev wbcomdev

View GitHub Profile
/**
* Change the default country on the checkout for non-existing users only.
*/
function wb_change_default_checkout_country( $country ) {
// If the user already exists, don't override country
if ( WC()->customer->get_is_paying_customer() ) {
return $country;
}
return 'DE'; // Override default to Germany (an example)
/**
* Add custom sorting options (asc/desc).
*/
function wb_custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( $orderby_value === 'random_list' ) {
$args['orderby'] = 'rand';
$args['order'] = '';
$args['meta_key'] = '';
}
/**
* Make price widget draggable on touch devices.
*/
function wb_load_touch_punch_js() {
global $version;
wp_enqueue_script( 'jquery-ui-widget' );
wp_enqueue_script( 'jquery-ui-mouse' );
wp_enqueue_script( 'jquery-ui-slider' );
wp_register_script( 'woo-jquery-touch-punch', get_stylesheet_directory_uri() . '/js/jquery.ui.touch-punch.min.js', array( 'jquery' ), $version, true );
wp_enqueue_script( 'woo-jquery-touch-punch' );
/**
* Remove product data tabs.
*/
function wb_woo_remove_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab.
unset( $tabs['reviews'] ); // Remove the reviews tab.
unset( $tabs['additional_information'] ); // Remove the additional information tab.
return $tabs;
/**
* Rename product data tabs.
*/
function wb_woo_rename_tabs( $tabs ) {
$tabs['description']['title'] = __( 'More Information' ); // Rename the description tab.
$tabs['reviews']['title'] = __( 'Ratings' ); // Rename the reviews tab.
$tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab.
return $tabs;
/**
* Reorder product data tabs.
*/
function wb_woo_reorder_tabs( $tabs ) {
$tabs['reviews']['priority'] = 5; // Reviews first.
$tabs['description']['priority'] = 10; // Description second.
$tabs['additional_information']['priority'] = 15; // Additional information third.
return $tabs;
/**
* Customize product data tabs.
*/
function wb_woo_custom_description_tab( $tabs ) {
$tabs['description']['callback'] = 'wb_woo_custom_description_tab_content'; // Custom description callback.
return $tabs;
}
/**
/**
* Add a custom product data tab.
*/
function wb_woo_new_product_tab( $tabs ) {
// Adds the new tab.
$tabs['test_tab'] = array(
/**
* Check if product has attributes, dimensions or weight to override the call_user_func() expects parameter 1 to be a valid callback error when changing the additional tab.
*/
function wb_woo_rename_tabs( $tabs ) {
global $product;
if ( $product->has_attributes() || $product->has_dimensions() || $product->has_weight() ) { // Check if product has attributes, dimensions or weight.
$tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab.
}
/**
* Hide category product count in product archives.
*/
add_filter( 'woocommerce_subcategory_count_html', '__return_false' );