Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Acephalia / svosp.css
Last active March 17, 2023 22:55
Show Variations On Woocommerce Shop Page
/* Variation drop down will need to be styled to match theme. Use this as a starting point. */
li.product-type-variable td {
float: left;
}
#main li.product input {
float: none;
}
@Acephalia
Acephalia / hpuspp.php
Created March 17, 2023 22:58
Woocommerce Hide Products Until A Specific Product Is Purchased
// Hide Products Until A Specific Product Is Purchased
function ghostie_pepper_until_purchase( $purchasing_product_id ) {
// Check if user has purchased the purchasing product
if ( wc_customer_bought_product( get_current_user_id(), $purchasing_product_id ) ) {
return;
}
// If not, hide the specified products
$products_to_hide = array( 123, 456, 789 ); // replace with your product IDs
@Acephalia
Acephalia / dopevp.php
Last active February 10, 2024 12:20
Woocommerce Disable Order Processing Email For Virtual Products
// Disable Order Processing Email For Virtual Products
add_action( 'woocommerce_checkout_process', 'virtual_products_that_dont_annoy_customers' );
function virtual_products_that_dont_annoy_customers() {
// Check if the cart contains virtual products only
$virtual_products_only = true;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( ! $cart_item['data']->is_virtual() ) {
@Acephalia
Acephalia / gist:873f1a6c13e842a8c62aa73a1b976231
Last active May 7, 2024 16:15
Auto Complete Woocommerce Virtual Orders
// Auto-complete virtual orders if payment is completed by u/acephaliax
function auto_complete_virtual_orders($order_id) {
if (!$order_id) {
return;
}
// Get the order object
$order = wc_get_order($order_id);
// Check if the order contains virtual products
@Acephalia
Acephalia / glusc.php
Last active May 20, 2023 22:37
Wordpress Greet Logged In User Shortcode
// Wordpress Greet Logged In User Shortcode
function detective_otter_found_you( $atts ) {
global $current_user, $user_login;
get_currentuserinfo();
if ($user_login) {
$display_name = '<a href="' . get_permalink( get_option('woocommerce_myaccount_page_id') ) . '">' . $current_user->display_name . '</a>';
return 'Hi ' . $display_name . ','; //Change Hi to desired greeting.
} else {
@Acephalia
Acephalia / Readme
Last active March 30, 2023 02:17
Disable search submit if field is empty
Change #searchform and #search to match your form fields.
@Acephalia
Acephalia / wtpteoh.css
Last active April 1, 2023 04:26
Truncate Woocommerce Product Titles & Expand on Hover
/* Truncate product titles */
.woocommerce ul.products li.product .woocommerce-loop-product__title,
.woocommerce-page ul.products li.product .woocommerce-loop-product__title {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
}
/* Expand truncated product titles on hover or focus */
@Acephalia
Acephalia / twpt.php
Last active April 1, 2023 04:26
Truncate Woocommerce Product Titles
add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 );
function shorten_woo_product_title( $title, $id ) {
if ( ! is_singular( array( 'product' ) ) && get_post_type( $id ) === 'product' && strlen( $title ) > 30 ) {
return substr( $title, 0, 30) . '…'; // change last number to the number of characters you want
} else {
return $title;
}
}
@Acephalia
Acephalia / acfwc.pho
Last active April 1, 2023 22:25
Add Custom Checkout Field Woocommerce
// Add custom checkout field
add_action('woocommerce_after_order_notes', 'howd_you_find_us_bro');
function howd_you_find_us_bro($checkout) {
echo '<div id="hdfoamb"><h3>' . __('How did you find my business?') . '</h3>';
woocommerce_form_field( 'customer_acquisition', array(
'type' => 'textarea',
'class' => array('my-field-class form-row-wide'),
@Acephalia
Acephalia / readme.txt
Last active April 4, 2023 05:48
Redirect to Seperate Thank You Page For 2 or More Items
Use snippet wcrtpf2omi2.php if you don't want the snippet to handle redirection for single products. Replace the $thankyou_page_url and $thankyou_multiple_page_url variables with the URLs of your custom thank you pages as needed.