Skip to content

Commit 59403c2

Browse files
committed
Initial commit
0 parents  commit 59403c2

File tree

6 files changed

+151
-0
lines changed

6 files changed

+151
-0
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# EditorConfig.org
2+
root = true
3+
4+
[**]
5+
charset = utf-8
6+
indent_style = tab
7+
indent_size = 4
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = false

assets/icon-128x128.png

1.42 KB
Loading

assets/icon-256x256.png

3.48 KB
Loading

assets/icon.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Plugin Name: Plain Formatted Billing Address for WooCommerce
4+
* Plugin URI: https://wordpress.org/plugins/plain-formatted-billing-address-for-woocommerce/
5+
* Description: Adds a plain-text formatted billing address placeholder to WooCommerce.
6+
* Version: 1.0.0
7+
* Requires at least: 5.0
8+
* Requires PHP: 7.2
9+
* Author: Maximum.Software
10+
* Author URI: https://maximum.software/
11+
* License: GPL v2 or later
12+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
13+
* Text Domain: plain-formatted-billing-address-for-woocommerce
14+
* WC requires at least: 3.0.0
15+
* WC tested up to: 9.6
16+
*/
17+
18+
// Exit if accessed directly
19+
if( ! defined( 'ABSPATH' ) )
20+
exit;
21+
22+
class Plain_Formatted_Billing_Address_for_WooCommerce
23+
{
24+
/**
25+
* Constructor for setting up the hooks
26+
*/
27+
public function __construct()
28+
{
29+
// Add hooks after WooCommerce is fully loaded
30+
add_action( 'woocommerce_init', array( $this, 'setup_hooks' ) );
31+
}
32+
33+
/**
34+
* Set up hooks
35+
*/
36+
public function setup_hooks()
37+
{
38+
add_filter( 'woocommerce_email_format_string', array( $this, 'process_formatted_billing_address_plain_placeholder' ), 10, 2 );
39+
}
40+
41+
/**
42+
* Build the billing address in plain-text format
43+
*
44+
* @param WC_Order $order The WooCommerce order object.
45+
* @return string A plain-text address with new line separators.
46+
*/
47+
private function get_plaintext_billing_address( $order )
48+
{
49+
// Compose the plain text billing address
50+
$lines = array_filter( array(
51+
trim( $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() ),
52+
$order->get_billing_company(),
53+
$order->get_billing_address_1(),
54+
$order->get_billing_address_2(),
55+
trim( $order->get_billing_city() . ', ' . $order->get_billing_state() . ' ' . $order->get_billing_postcode() ),
56+
$order->get_billing_country(),
57+
) );
58+
59+
// Join with new line characters
60+
return implode( "\n", $lines );
61+
}
62+
63+
/**
64+
* Replace our custom placeholder `{formatted_billing_address_plain}` with a plain-text billing address.
65+
*
66+
* Hooked into 'woocommerce_email_format_string'.
67+
*
68+
* @param string $string The email string (subject/body/heading/etc.).
69+
* @param mixed $email The email object (or some data) from WooCommerce.
70+
* @return string
71+
*/
72+
public function process_formatted_billing_address_plain_placeholder( $string, $email )
73+
{
74+
// Bail if the placeholder is not found
75+
if( false === strpos( $string, '{formatted_billing_address_plain}' ) )
76+
return $string;
77+
78+
// Safely detect the order object from $email
79+
$order = ( is_object( $email ) && property_exists( $email, 'object' ) ) ? $email->object : null;
80+
81+
// If an order is found, replace the placeholder
82+
if( $order && is_a( $order, 'WC_Order' ) )
83+
{
84+
// Build a plain-text billing address
85+
$address_string_plaintext = $this->get_plaintext_billing_address( $order );
86+
87+
// Replace our custom placeholder
88+
$string = str_replace(
89+
'{formatted_billing_address_plain}',
90+
$address_string_plaintext,
91+
$string
92+
);
93+
}
94+
95+
return $string;
96+
}
97+
}
98+
99+
$plain_formatted_billing_address_for_woocommerce = new Plain_Formatted_Billing_Address_for_WooCommerce();

readme.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
=== Plain Formatted Billing Address for WooCommerce ===
2+
Version: 1.0.0
3+
Stable tag: 1.0.0
4+
Requires at least: 5.0
5+
Tested up to: 6.7
6+
Requires PHP: 7.2
7+
Tags: woocommerce, billing address, formatted billing address, plain text, formatting
8+
Plugin URI: https://wordpress.org/plugins/plain-formatted-billing-address-for-woocommerce/
9+
Author: Maximum.Software
10+
Author URI: https://maximum.software
11+
License: GPLv2 or later
12+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
13+
14+
Adds a plain-text formatted billing address placeholder to WooCommerce.
15+
16+
== Description ==
17+
18+
The 'Plain Formatted Billing Address for WooCommerce' plugin adds a custom email placeholder `{formatted_billing_address_plain}` that works just like the built-in `{formatted_billing_address}`, but outputs the billing address in plain text format (joined by new line characters) instead of using HTML formatting.
19+
20+
This is particularly useful when you need to use addresses in contexts where HTML is not supported or desired.
21+
22+
= Usage =
23+
24+
Simply use the `{formatted_billing_address_plain}` placeholder in your WooCommerce email templates wherever you need a plain-text formatted billing address.
25+
26+
= Requirements =
27+
28+
* WordPress 5.0 or higher
29+
* WooCommerce 3.0.0 or higher
30+
* PHP 7.2 or higher
31+
32+
== Installation ==
33+
34+
1. Upload the plugin files to the `/wp-content/plugins/plain-formatted-billing-address-for-woocommerce` directory, or install the plugin through the WordPress plugins screen directly.
35+
2. Activate the plugin through the 'Plugins' screen in WordPress
36+
3. Use the placeholder `{formatted_billing_address_plain}` in your WooCommerce email templates
37+
38+
== Changelog ==
39+
40+
= 1.0.0 =
41+
* Initial release

0 commit comments

Comments
 (0)