Skip to content

Instantly share code, notes, and snippets.

View roykho's full-sized avatar
:dependabot:

Roy Ho roykho

:dependabot:
View GitHub Profile
@roykho
roykho / gist:14c57ab320b2f999e86bb0b531b2e55a
Last active April 17, 2023 12:58
WooCommerce: Delete old lingering admin notices
// Use these instructions at your own risk. Make sure you have full site/database backup prior to proceeding.
//
// Install this plugin to add custom PHP code https://wordpress.org/plugins/code-snippets/
// Activate the plugin.
// Go to Snippets->Add New
// Paste the following code into the provided "Code" field.
// Choose to Run Only Once.
// Click Save changes and activate button at the bottom.
// After running it once, I would suggest to remove this snippet otherwise you may miss out on important updates in the future.
// After running this, you may get a fresh copy of the notices once more. This is normal and this time when you dismiss them, they should stay gone..
@roykho
roykho / stripe-pre-4.1.14-styles.txt
Last active February 5, 2024 11:58
Stripe Pre 4.1.14 Styles
#add_payment_method .woocommerce-PaymentMethod label { margin-left: 10px; }
#add_payment_method li { clear: right; }
#add_payment_method #wc-stripe_sepa-form { padding: 10px; }
form#order_review #payment_method_stripe { margin: 25px 0 25px 25px; }
form#order_review #payment_method_stripe_sepa { margin: 25px 0 25px 25px; }
form#order_review .payment_methods label { margin-left: 10px; }
form#order_review li { clear: right; }
form#order_review #wc-stripe_sepa-form { padding: 10px; }
.wc_payment_method .payment_box label { display: inline; }
@roykho
roykho / gist:b5e6849adacd9970fc6f
Last active September 10, 2020 17:01
WooCommerce Product Vendors 2.0 - Add columns to WooCommerce Customer and Orders CSV Export
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_product_vendors_csv_export_integration_add_column_headers' );
add_filter( 'wc_customer_order_csv_export_order_line_item', 'wc_product_vendors_csv_export_integration_modify_line_item', 10, 5 );
add_filter( 'wc_customer_order_csv_export_order_row_one_row_per_item', 'wc_product_vendors_csv_export_integration_add_row_data', 10, 4 );
function wc_product_vendors_csv_export_integration_add_column_headers( $headers ) {
$headers['vendor'] = 'Vendor';
return $headers;
@roykho
roykho / gist:1062c708af772412fe7e
Last active October 28, 2022 16:01
WooCommerce: Remove related products when up-sell products are defined
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
add_action( 'woocommerce_after_single_product_summary', 'related_upsell_products', 15 );
function related_upsell_products() {
global $product;
if ( isset( $product ) && is_product() ) {
$upsells = version_compare( WC_VERSION, '3.0', '<' ) ? $product->get_upsells() : $product->get_upsell_ids();
@roykho
roykho / gist:1ff00214a1e10ac0cff4
Created August 5, 2014 20:31
WooCommerce: How to remove shipping label in cart and checkout
add_filter( 'woocommerce_cart_shipping_method_full_label', 'remove_shipping_label', 10, 2 );
function remove_shipping_label( $label, $method ) {
$new_label = preg_replace( '/^.+:/', '', $label );
return $new_label;
}
@roykho
roykho / gist:39c1d1a9ee992bef3629
Created July 30, 2014 13:04
WooCommerce: How to reverse product review comments order
add_filter( 'woocommerce_product_review_list_args', 'wc_reverse_product_reviews' );
function wc_reverse_product_reviews( $args ) {
$args['reverse_top_level'] = true;
return $args;
}
@roykho
roykho / gist:ec36afdf004f5efcf7a9
Created June 5, 2014 21:02
WooCommerce: Link external products to detail product page from product category list
add_filter( 'woocommerce_loop_add_to_cart_link', 'product_cat_external', 10, 2 );
function product_cat_external( $html, $product ) {
if ( $product->product_type === 'external' ) {
return '<a href="' . get_post_permalink( $product->id ) . '" rel="nofollow" data-product_id="' . esc_attr( $product->id ) . '" data-product_sku="' . esc_attr( $product->get_sku() ) . '" class="button add_to_cart_button product_type_variable">View Detail</a>';
} else {
return $html;
}
}
@roykho
roykho / gist:9376546
Created March 5, 2014 21:04
WooCommerce: Remove Dimension/Weight from product detail page
add_filter( 'wc_product_enable_dimensions_display', '__return_false' );
@roykho
roykho / gist:9332257
Created March 3, 2014 19:05
WooCommerce: Change add to cart text and link to redirect to single product page
add_filter( 'woocommerce_loop_add_to_cart_link', 'change_add_to_cart_loop' );
function change_add_to_cart_loop( $product ) {
global $product; // this may not be necessary as it should have pulled the object in already
return '<a href="' . esc_url( $product->get_permalink( $product->id ) ) . '">LEARN MORE</a>';
}
@roykho
roykho / gist:9292693
Last active December 5, 2023 13:59
WooCommerce: How to remove star review rating under the product title when enable review is off.
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'my_woocommerce_template_single_rating', 10 );
function my_woocommerce_template_single_rating() {
global $product;
if ( $product->post->comment_status === 'open' )
wc_get_template( 'single-product/rating.php' );