This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'woocommerce_before_calculate_totals', 'custom_cart_price' ); | |
function custom_cart_price( $cart_object ) { | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
foreach ( $cart_object->get_cart() as $key => $value ) { | |
// CHANGE PRICE FOR ALL CART ITEMS TO 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// MODIFY PRICE | |
add_filter( 'woocommerce_cart_item_price', 'custom_price_display', 10, 3 ); | |
function custom_price_display( $price, $cart_item, $cart_item_key ) { | |
// ADD ' FOR EACH ITEM' SUFFIX TO ALL PRODUCTS | |
$price .= ' for each item'; | |
// ADD ' FOR THIS ITEM' SUFFIX TO SPECIFIC PRODUCT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
$product = $cart_item['data']; | |
// GET ITEM LINK | |
$link = $product->get_permalink( $cart_item ); | |
// GET ITEM CART PRICE | |
$price = WC()->cart->get_product_price( $product ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$product_id = 15; // Replace with your product id | |
$product_cart_id = WC()->cart->generate_cart_id( $product_id ); | |
if( ! WC()->cart->find_product_in_cart( $product_cart_id ) ){ | |
// Do something | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_get_cart_url', 'custom_cart_url' ); | |
function custom_cart_url( $url ) { | |
$url = '/new-cart-link/'; | |
return $url; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Full list: https://www.businessbloomer.com/woocommerce-get-cart-info-total-items-etc-from-cart-object/ | |
wc_get_cart_url(); // GET CART URL | |
WC()->cart->is_empty(); // CHECK IF CART IS EMPTY | |
WC()->cart->needs_shipping(); // CHECK IF CART NEEDS SHIPPING | |
WC()->cart->needs_shipping_address(); // CHECK IF CART NEEDS SHIPPING ADDRESS | |
WC()->cart->has_discount( $coupon_code ); // CHECK IF CART HAS SPECIFIC COUPON CODE APPLIED | |
WC()->cart->get_cart_contents_count(); // GET CART COUNT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter ( 'woocommerce_account_menu_items', 'remove_my_account_links' ); | |
function remove_my_account_links( $menu_links ){ | |
unset( $menu_links['tab-slug-to-be-removed'] ); | |
$menu_links['tab-slug-to-be-renamed'] = 'New Name'; | |
return $menu_links; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// SETS NUMBER OF PRODUCTS DISPLAYED PER PAGE | |
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 9999 ); | |
function new_loop_shop_per_page( $cols ) { | |
$cols = 30; | |
return $cols; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// orderby values are date, menu_order, popularity, rating, date, price, price-desc | |
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby', 20 ); | |
function custom_woocommerce_catalog_orderby( $orderby ) { | |
unset($orderby["price"]); // Remove price option | |
return $orderby; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// orderby values are date, menu_order, popularity, rating, date, price, price-desc | |
add_filter( 'woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby' ); | |
function custom_default_catalog_orderby() { | |
if ( is_product_category( array( 'category-1-slug', 'category-2-slug' ) ) ) { // Replace with your category slugs | |
return 'menu_order'; | |
} else { | |
return 'date'; |