Skip to content

Instantly share code, notes, and snippets.

View display-sale-badge-percent-discout.php
<?php
add_filter( 'woocommerce_sale_flash', 'add_percentage_to_sale_badge', 20, 3 );
function add_percentage_to_sale_badge( $html, $post, $product ) {
if( $product->is_type('variable')){
$percentages = array();
// Get all variation prices
$prices = $product->get_variation_prices();
// Loop through variation prices
View add_google_analytics_to_wordpress.php
<?php
add_action( 'wp_head', 'musilda_ga_code' );
function musilda_ga_code(){
?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-169040585-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
View get_order_weight_woocommerce.php
<?php
//Save cart weight
add_action( 'woocommerce_checkout_update_order_meta', 'musilda_save_cart_weight' );
function musilda_save_cart_weight( $order_id ) {
$weight = WC()->cart->get_cart_contents_weight();
update_post_meta( $order_id, 'order-weight', $weight );
}
//Update all orders
$args = array(
View Add_sortable_field_to admin_order.php
<?php
add_filter( 'manage_edit-shop_order_sortable_columns', 'musilda_order_sortable_column' );
function musilda_order_sortable_column( $columns ) {
$columns = array( 'order-weight' => 'order-weight' );
return $columns;
}
View show_custom_column_to_woocommerce_orders.php
<?php
add_action( 'manage_shop_order_posts_custom_column', 'musilda_show_weight_in_order_column' );
function musilda_show_weight_in_order_column( $column ) {
global $post;
if ( empty( $post->ID ) ) {
return;
}
View add_custom_column_to_woocommerce_orders.php
<?php
add_filter( 'manage_shop_order_posts_columns', 'musilda_custom_order_column', 11 );
function musilda_custom_order_column( $columns ) {
$expanded_columns = [];
foreach ( $columns as $key => $value ) {
$expanded_columns[$key] = $value;
if ( $key == 'name' ) {
View replace-woocommerce-breadcrumb.php
<?php
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
add_action( 'woocommerce_before_main_content', 'musilda_yoast_breadcrumb', 20, 0);
function musilda_yoast_breadcrumb() {
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<nav class="woocommerce-breadcrumb">','</nav>');
}
}
View woocommerce-change-add-to-cart-text.php
<?php
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text', 999 );
function woo_custom_cart_button_text( $text ) {
foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if( get_the_ID() == $_product->get_id() ) {
return 'Produkt je již v košíku - přidat znovu?' ;
View change-cross-sells-products.php
<?php
//Remove cross sells products
remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
//Change cross sells columns number
add_filter( 'woocommerce_cross_sells_columns', 'musilda_change_cross_sells_columns' );
function musilda_change_cross_sells_columns( $columns ) {
return 3;
}
//Change number of cross sell products
add_filter( 'woocommerce_cross_sells_total', 'musilda_change_cross_sells_product_number' );
View shop-stock-product-first-woocommerce.php
<?php
//Change sorting
add_filter( 'woocommerce_get_catalog_ordering_args', 'musilda_show_instock_products_first', 9999, 3 );
function musilda_show_instock_products_first( $args, $orderby, $order ) {
if( $orderby == 'stock_status' ){
$args['orderby'] = 'meta_value';
$args['order'] = 'ASC';
$args['meta_key'] = '_stock_status';
You can’t perform that action at this time.