Skip to content

Instantly share code, notes, and snippets.

@passatgt
passatgt / orders-google-map.php
Created December 28, 2023 12:27
Save coordinates of the billing address and show them on a map
<?php
//Save coorindates of the billing address when order marked completed using google geocode API and save it to order meta
add_action('woocommerce_order_status_completed', function($order_id) {
$order = wc_get_order($order_id);
$billing_address = $order->get_formatted_billing_address();
// Replace spaces with '+' for URL encoding
$formatted_address = str_replace(' ', '+', $billing_address);
$api_key = 'YOUR GOOGLE API KEY';
@passatgt
passatgt / shipping-cache-test-block.php
Created December 5, 2023 17:09
Shipping rate test plugin for checkout blocks bug(?)
<?php
/*
Plugin Name: shipping-cache-test-block
Version: 1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@passatgt
passatgt / validate-wc-hu-postcodes.php
Last active November 15, 2023 09:42
Validate hungarian postcodes in WooCommerce
<?php
add_filter('woocommerce_validate_postcode', function($valid, $postcode, $country){
if($country != 'HU') return $valid;
$postcode = intval($postcode);
$valid_postcodes = array(1007, 1011, 1012, 1013, 1014, 1015, 1016, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1051, 1052, 1053, 1054, 1055, 1056, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1121, 1122, 1123, 1124, 1125, 1126, 1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1161, 1162, 1163, 1164, 1165, 1171, 1172, 1173, 1174, 1181, 1182, 1183, 1184, 1185, 1186, 1188, 1191, 11
@passatgt
passatgt / CustomShortcutsLink.swift
Last active April 4, 2023 15:44
Custom ShortcutsLink in your SwiftUI Form
@passatgt
passatgt / wc-my-orders-products-search.php
Created September 9, 2022 15:57
WooCommerce product search for My Account / Orders
//Create search bar on the top of the my account / orders page
add_action('woocommerce_before_account_orders', function(){
?>
<form method="get">
<input type="text" name="keyword" placeholder="Keresés" value="<?php echo esc_attr($_GET['keyword']); ?>">
<input type="submit" value="Keresés" />
</form>
<?php
$customer_orders = false;
@passatgt
passatgt / add-to-cart-form-shortcode.php
Created August 26, 2021 20:11
WooCommerce Add To Cart Form Shortcode that supports variable products too
add_shortcode( 'add-to-cart-form', function($atts) {
global $post;
//Get shortcode attributes
$a = shortcode_atts( array(
'id' => 0
), $atts );
//Find the product and set it to global
$product_data = get_post( $a['id'] );
@passatgt
passatgt / wc-custom-store-management-link.js
Created April 3, 2021 12:38
jQuery way to add custom storage management links in WooCommerce dashboard
@passatgt
passatgt / shop_order_info_column.php
Created May 29, 2020 12:11
Add order item details into the order manager table in WooCommerce
add_filter( 'manage_edit-shop_order_columns', function($columns) {
$columns['order_info'] = 'Rendelés infók';
return $columns;
});
add_action( 'manage_shop_order_posts_custom_column', function( $column ) {
global $the_order;
if ( 'order_info' === $column ) {
echo $the_order->get_billing_email();
$line_items = $the_order->get_items();
@passatgt
passatgt / wc-only-checkout.php
Created May 28, 2020 11:38
Use WooCommerce with only a checkout page
<?php
/*
I built custom product pages with a simple add to cart button(using the add_to_cart shortcode) for a webshop.
There was no need for category pages, shop pages, cart or anything like that, just a simple product page with an add to cart button that redirects to checkout directly.
Here is how you can do this:
1. Delete the My Account page
2. Delete the Shop page
*/
@passatgt
passatgt / vp-products-pdf-pricelist.php
Created May 18, 2020 10:50
Creates a new page under WooCommerce to display a list of all the products and prices, which you can print out for a simple pricelist.
<?php
/*
Plugin Name: VP Árlista export
Plugin URI: http://visztpeter.me
Author: Viszt Péter
Version: 1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly