Skip to content

Instantly share code, notes, and snippets.

@SirDarcanos
SirDarcanos / 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 );
}
@SirDarcanos
SirDarcanos / 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' );
}
@SirDarcanos
SirDarcanos / 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;
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;
}
@SirDarcanos
SirDarcanos / functions.php
Last active October 30, 2023 07:51
How To Disable Payments on WooCommerce
<?php
add_filter( 'woocommerce_cart_needs_payment', '__return_false' );
@SirDarcanos
SirDarcanos / 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 );
}
@SirDarcanos
SirDarcanos / 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' );
@SirDarcanos
SirDarcanos / 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'; } );
@SirDarcanos
SirDarcanos / functions.php
Last active October 30, 2023 07:43
Change the Out of stock string based on the product's cost
<?php
add_filter( 'woocommerce_get_availability_text', 'price_out_of_stock_string', 10, 2 );
function price_out_of_stock_string( $text, $product ) {
if ( $text === 'Out of stock' && $product->get_price() < 100 ) {
return "Out of stock because of The Queen's Gambit";
}
return $text;
}
@SirDarcanos
SirDarcanos / functions.php
Last active October 30, 2023 07:42
How to Change the Continue Shopping Redirect URL
<?php
add_filter( 'woocommerce_continue_shopping_redirect', function() { return get_home_url(); } );