Skip to content

Instantly share code, notes, and snippets.

View SiR-DanieL's full-sized avatar

Nicola Mustone SiR-DanieL

View GitHub Profile
@SiR-DanieL
SiR-DanieL / functions.php
Last active October 30, 2023 07:48
Reordering Cross-Sells and Up-Sells in WooCommerce
<?php
// Up-sells sorting
add_filter( 'woocommerce_upsells_orderby', function() { return 'date'; } );
add_filter( 'woocommerce_upsells_order', function() { return 'desc'; } );
// Cross-sells sorting
add_filter( 'woocommerce_cross_sells_orderby', function() { return 'date'; } );
add_filter( 'woocommerce_cross_sells_order', function() { return 'desc'; } );
@SiR-DanieL
SiR-DanieL / functions.php
Last active October 30, 2023 07:49
Calculate Shipping After Discounts with Table Rate Shipping
<?php
add_filter( 'woocommerce_table_rate_compare_price_limits_after_discounts', '__return_true' );
@SiR-DanieL
SiR-DanieL / functions.php
Last active October 30, 2023 07:50
Remove the "nofollow" From the Recent Comments
<?php
/**
* Remove the "nofollow" attribute from all comments author's links
* except for a specific author.
*/
function dofollow_blog_author_comment( $return, $author ) {
if ( $author === 'Your Name' ) {
$return = str_replace( "rel='external nofollow ugc'", '', $return );
}
@SiR-DanieL
SiR-DanieL / functions.php
Last active October 30, 2023 07:51
How To Disable Payments on WooCommerce
<?php
add_filter( 'woocommerce_cart_needs_payment', '__return_false' );
add_filter( 'woocommerce_order_barcodes_barcode_string', 'change_barcode_text' );
function change_barcode_text( $barcode_string ) {
$barcode_class = WooCommerce_Order_Barcodes::get_instance();
$order_id = barcode_class->get_barcode_order( $barcode_string );
return $order_id;
}
@SiR-DanieL
SiR-DanieL / functions.php
Last active October 30, 2023 10:07
How to limit purchases to one per order
<?php
add_filter( 'woocommerce_add_to_cart_validation', 'wc_limit_one_per_order', 10, 2 );
function wc_limit_one_per_order( $passed_validation, $product_id ) {
if ( 31 !== $product_id ) {
return $passed_validation;
}
if ( WC()->cart->get_cart_contents_count() >= 1 ) {
wc_add_notice( __( 'This product cannot be purchased with other products. Please, empty your cart first and then add it again.', 'woocommerce' ), 'error' );
return false;
@SiR-DanieL
SiR-DanieL / functions.php
Last active October 30, 2023 07:54
Disable Enfold Portfolio
<?php
add_action( 'after_setup_theme', 'remove_portfolio' );
function remove_portfolio() {
remove_action( 'init', 'portfolio_register' );
}
@SiR-DanieL
SiR-DanieL / functions.php
Last active October 30, 2023 10:09
WordPress Discord Post: Send only specific categories
<?php
add_filter( 'wp_discord_post_is_new_post', 'wp_discord_post_limit_by_category' );
function wp_discord_post_limit_by_category( $post ) {
return has_category( array( 'Category 1', 'Category 2' ), $post );
}
@SiR-DanieL
SiR-DanieL / functions.php
Last active October 30, 2023 10:09
WordPress Discord Post: Send only specific categories
<?php
add_filter( 'wp_discord_post_is_new_post', 'wp_discord_post_limit_by_category' );
function wp_discord_post_limit_by_category( $post ) {
return has_category( 'Your Category Name', $post );
}
@SiR-DanieL
SiR-DanieL / functions.php
Last active October 30, 2023 07:56
Add an Empty Cart Button in WooCommerce
<?php
add_action( 'wp_loaded', 'woocommerce_empty_cart_action', 20 );
function woocommerce_empty_cart_action() {
if ( isset( $_GET['empty_cart'] ) && 'yes' === esc_html( $_GET['empty_cart'] ) ) {
WC()->cart->empty_cart();
$referer = wp_get_referer() ? esc_url( remove_query_arg( 'empty_cart' ) ) : wc_get_cart_url();
wp_safe_redirect( $referer );
}
}