Skip to content

Instantly share code, notes, and snippets.

@bradleysa
bradleysa / gist:d401339205f9f695e0d7a0f085ebaa5f
Created April 22, 2022 07:50
WC: Social Media Icons on Product Pages
add_action( 'woocommerce_share', 'patricks_woocommerce_social_share_icons', 10 );
function patricks_woocommerce_social_share_icons() {
if ( function_exists( 'sharing_display' ) ) {
remove_filter( 'the_content', 'sharing_display', 19 );
remove_filter( 'the_excerpt', 'sharing_display', 19 );
echo sharing_display();
}
}
/** http://speakinginbytes.com/2014/12/social-media-icons-woocommerce-products/ **/
add_filter('woocommerce_enable_order_notes_field', '__return_false');
/** http://stackoverflow.com/questions/22483312/woocommerce-removing-additional-information-name-on-checkout-page **/
@bradleysa
bradleysa / gist:055e501f3970cc04b61421cf7c5e911d
Created April 22, 2022 07:54
WC: Change 'add to cart' text on archives depending on product type
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
function custom_woocommerce_product_add_to_cart_text() {
global $product;
$product_type = $product->product_type;
switch ( $product_type ) {
case 'external':
return __( 'Take me to their site!', 'woocommerce' );
break;
@bradleysa
bradleysa / gist:29f550cd6103f966f8bd92851cd2c0b8
Created April 22, 2022 07:54
WC: Personalizing the thank you page title
function rp4wp_title_order_received( $title, $id ) {
if ( is_order_received_page() && get_the_ID() === $id ) {
global $wp;
$order_id = apply_filters( 'woocommerce_thankyou_order_id', absint( $wp->query_vars['order-received'] ) );
$order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( $_GET['key'] ) );
if ( $order_id > 0 ) {
$order = wc_get_order( $order_id );
if ( $order->order_key != $order_key ) {
@bradleysa
bradleysa / gist:a67971142e4b31472574ac8833740859
Created April 22, 2022 07:55
WC: Hide USPS when Free Shipping is available
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
@bradleysa
bradleysa / gist:2e3915dfb19dd5ce94034e6c45a00af6
Created April 22, 2022 07:56
WC: Add attributes to checkout fields
// Add attributes to checkout fields
function wc_add_checkout_add_ons_attributes( $checkout_fields ) {
$add_on_id = 2; // change number to correct add-on id
if ( isset( $checkout_fields['add_ons'][ 'wc_checkout_add_ons_' . $add_on_id ] ) ) {
$checkout_fields['add_ons'][ 'wc_checkout_add_ons_' . $add_on_id ]['placeholder'] = "Add a short message for a handwritten card (optional)";
//Adds placeholder text
}
@bradleysa
bradleysa / gist:e2574b193032d3be40cd5b0b3c78b10f
Created April 22, 2022 07:57
WC: Custom Low Stock message
/* Change the 'Only # left in stock' message on the WooCommerce product page to
* simply show 'Low Stock'.
* Add to your theme's functions.php file
*/
function custom_stock_totals($availability_html, $availability_text, $product) {
if (substr($availability_text,0, 4)=="Only") {
$availability_text = "Supplies are running low! Get your jam!";
}
$availability_html = '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability_text ) . '</p>';
return $availability_html;
@bradleysa
bradleysa / gist:c8f099408d417da58cb538e452f19414
Created April 22, 2022 07:58
WC: Disable WooCommerce From: $$ Price
function patricks_custom_variation_price( $price, $product ) {
$target_product_types = array(
'variable'
);
if ( in_array ( $product->product_type, $target_product_types ) ) {
// if variable product return and empty string
return '';
}
@bradleysa
bradleysa / gist:6cc0c1ddec5bc90c33f6e6db80ed3c03
Created April 22, 2022 07:59
Advanced Random Posts Widget style
function prefix_remove_arpw_style() {
wp_dequeue_style( 'arpw-style' );
}
add_action( 'wp_enqueue_scripts', 'prefix_remove_arpw_style', 10 );
/** https://wordpress.org/plugins/advanced-random-posts-widget/faq/ **/
@bradleysa
bradleysa / gist:a0703ca85e49bedf97c7ea2c12b5960a
Created April 22, 2022 08:00
WC: Remove "Default Sorting" Dropdown
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
/** https://www.businessbloomer.com/woocommerce-remove-default-sorting-dropdown/ **/