Skip to content

Instantly share code, notes, and snippets.

View vishalck's full-sized avatar

Vishal Kothari vishalck

View GitHub Profile
@vishalck
vishalck / woocommerce-custom-thank-you-page-redirect.php
Last active October 8, 2024 22:19
Redirect to Custom Thank You page in WooCommerce
<?php
add_action( 'template_redirect', 'woo_custom_redirect_after_purchase' );
function woo_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && !empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( 'http://localhost:8888/woocommerce/custom-thank-you/' );
exit;
}
}
@vishalck
vishalck / change-title-woocommerce-order-received-page.php
Last active January 26, 2023 21:05
Change Title of WooCommerce Thank You page
<?php
add_filter( 'the_title', 'woo_title_order_received', 10, 2 );
function woo_title_order_received( $title, $id ) {
if ( function_exists( 'is_order_received_page' ) &&
is_order_received_page() && get_the_ID() === $id ) {
$title = "Thank you for your order! :)";
}
return $title;
@vishalck
vishalck / personalize-woocommerce-thank-you-page.php
Last active October 8, 2024 22:20
Personalize the WooCommerce Thank You page
<?php
add_filter( 'the_title', 'woo_personalize_order_received_title', 10, 2 );
function woo_personalize_order_received_title( $title, $id ) {
if ( is_order_received_page() && get_the_ID() === $id ) {
global $wp;
// Get the order. Line 9 to 17 are present in order_received() in includes/shortcodes/class-wc-shortcode-checkout.php file
$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'] ) );
@vishalck
vishalck / woocommerce-change-order-received-text.php
Last active November 5, 2018 16:55
Change Text on Order Received page in WooCommerce
<?php
add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 );
function woo_change_order_received_text( $str, $order ) {
$new_str = $str . ' We have emailed the purchase receipt to you.';
return $new_str;
}
@vishalck
vishalck / woocommerce-change-order-received-text2.php
Created May 23, 2017 10:39
Change Text & Add External Link on Order Received Page in WooCommerce
<?php
add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 );
function woo_change_order_received_text( $str, $order ) {
$new_str = 'We have emailed the purchase receipt to you. Please make sure to fill <a href="http://localhost:8888/some-form.pdf">this form</a> before attending the event';
return $new_str;
}
@vishalck
vishalck / failed-purchase.php
Created May 23, 2017 11:25
Failed purchase file when creating custom Thank You page for WooCommerce
<p><?php _e( 'There was a problem processing your order. Your transaction has been declined.', 'woocommerce' ); ?></p>
<p>
<?php
_e( 'Please attempt your purchase again.', 'woocommerce' );
?>
</p>
<p>
<a href="<?php echo esc_url( $order->get_checkout_payment_url() ); ?>" class="button pay"><?php _e( 'Try Again', 'woocommerce' ) ?></a>
@vishalck
vishalck / thankyou.php
Created May 23, 2017 14:00
Custom thankyou.php template in WooCommerce
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div class="woocommerce-order">
<?php if ( $order ) : ?>
@vishalck
vishalck / woocommerce-add-new-column-on-orders-page.php
Last active August 15, 2019 09:05
Add new column to WooCommerce Orders page
<?php
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION( $columns ) {
$new_columns = ( is_array( $columns ) ) ? $columns : array();
unset( $new_columns[ 'order_actions' ] );
//edit this for your column(s)
//all of your columns will be added before the actions column
$new_columns['MY_COLUMN_ID_1'] = 'MY_COLUMN_1_TITLE';
@vishalck
vishalck / woocommerce-sort-custom-columns-orders-page.php
Last active June 12, 2017 12:49
Make custom columns sortable
<?php
add_filter( "manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION' );
function MY_COLUMNS_SORT_FUNCTION( $columns )
{
$custom = array(
'MY_COLUMN_ID_1' => 'MY_COLUMN_1_POST_META_ID',
'MY_COLUMN_ID_2' => 'MY_COLUMN_2_POST_META_ID'
);
return wp_parse_args( $custom, $columns );
@vishalck
vishalck / woocommerce-populate-custom-order-columns.php
Last active June 12, 2017 12:58
Populate custom order columns with data
<?php
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
function MY_COLUMNS_VALUES_FUNCTION( $column ) {
global $post;
$data = get_post_meta( $post->ID );
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code