yaymail
/
src
/
Integrations
/
F4ShippingPhoneAndEmailForWooCommerce
/
F4ShippingPhoneAndEmailForWooCommerce.php
F4ShippingPhoneAndEmailForWooCommerce.php in YayMail – WooCommerce Email Customizer 4.4.1, at src/Integrations/F4ShippingPhoneAndEmailForWooCommerce/F4ShippingPhoneAndEmailForWooCommerce.php
| 1 | <?php |
| 2 | |
| 3 | namespace YayMail\Integrations\F4ShippingPhoneAndEmailForWooCommerce; |
| 4 | |
| 5 | use YayMail\Utils\SingletonTrait; |
| 6 | |
| 7 | /** |
| 8 | * F4 Shipping Phone and E-Mail for WooCommerce |
| 9 | * Link: https://en-ca.wordpress.org/plugins/f4-woocommerce-shipping-phone-and-e-mail/ |
| 10 | * |
| 11 | * F4ShippingPhoneAndEmailForWooCommerce |
| 12 | * * @method static F4ShippingPhoneAndEmailForWooCommerce get_instance() |
| 13 | */ |
| 14 | class F4ShippingPhoneAndEmailForWooCommerce { |
| 15 | use SingletonTrait; |
| 16 | |
| 17 | private function __construct() { |
| 18 | if ( self::is_3rd_party_installed() ) { |
| 19 | $this->initialize_hooks(); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | public static function is_3rd_party_installed() { |
| 24 | return class_exists( 'F4\WCSPE\Core\Hooks' ); |
| 25 | } |
| 26 | |
| 27 | private function initialize_hooks() { |
| 28 | add_filter( 'yaymail_shipping_address_content', [ $this, 'add_shipping_phone_and_email_to_shipping_address' ], 10, 2 ); |
| 29 | } |
| 30 | |
| 31 | public function add_shipping_phone_and_email_to_shipping_address( $shipping_address, $order ) { |
| 32 | |
| 33 | $shipping_phone = $order->get_shipping_phone(); |
| 34 | $shipping_email = $order->get_meta( '_shipping_email' ); |
| 35 | |
| 36 | if ( ! empty( $shipping_phone ) ) { |
| 37 | if ( strpos( $shipping_address, '<a href="tel:' . esc_attr( $shipping_phone ) . '">' ) === false ) { |
| 38 | $html_shipping_phone = '<a class="yaymail-shipping-phone" href="tel:' . esc_attr( $shipping_phone ) . '">' . esc_html( $shipping_phone ) . '</a>'; |
| 39 | $shipping_address = str_replace( $shipping_phone, $html_shipping_phone, $shipping_address ); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | if ( ! empty( $shipping_email ) ) { |
| 44 | if ( strpos( $shipping_address, '<a href="mailto:' . esc_attr( $shipping_email ) . '">' ) === false ) { |
| 45 | $html_shipping_email = '<a class="yaymail-shipping-email" href="mailto:' . esc_attr( $shipping_email ) . '">' . esc_html( $shipping_email ) . '</a>'; |
| 46 | $shipping_address = str_replace( $shipping_email, $html_shipping_email, $shipping_address ); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | $shipping_address = trim( $shipping_address ); |
| 51 | |
| 52 | return $shipping_address; |
| 53 | } |
| 54 | } |
| 55 |