Created
February 24, 2025 15:02
-
-
Save rwkyyy/74199b69b3578951a2da04e6492fb0a9 to your computer and use it in GitHub Desktop.
Afișare Denumire Locker Sameday în Mail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Helper first | |
function getLockerNameSameday( $locker_id ) { | |
if ( empty( $locker_id ) ) { | |
return 'Locker necunoscut'; | |
} | |
if ( class_exists( 'SamedayCourierQueryDb' ) ) { | |
// Determine if it's a test environment | |
$is_testing = get_option( 'sameday_testing_mode', 'no' ) === 'yes' ? 1 : 0; | |
$locker = SamedayCourierQueryDb::getLockerSameday( $locker_id, $is_testing ); | |
if ( ! empty( $locker ) && isset( $locker->name ) ) { | |
return $locker->name; | |
} | |
} | |
return 'Locker necunoscut'; | |
} | |
//locker mail | |
add_action( 'woocommerce_email_before_order_table', 'add_easybox_locker_to_email', 15, 4 ); | |
function add_easybox_locker_to_email( $order, $sent_to_admin, $plain_text, $email ) { | |
if ( ! is_a( $order, 'WC_Order' ) ) { | |
return; | |
} | |
$sameday_meta = get_post_meta( $order->get_id(), '_sameday_shipping_locker_id', true ); | |
$sameday_data = json_decode( $sameday_meta, true ); | |
$samedayId = isset( $sameday_data['lockerId'] ) ? $sameday_data['lockerId'] : null; | |
if ( ! empty( $samedayId ) ) { | |
$SameDayLockerName = getLockerNameSameday( $samedayId ); // Ensure this function exists | |
if ( ! empty( $SameDayLockerName ) ) { | |
$message = '<p><strong>Easybox selectat:</strong> ' . esc_html( $SameDayLockerName ) . '</p>'; | |
if ( $plain_text ) { | |
echo "Easybox selectat: " . esc_html( $SameDayLockerName ) . "\n"; | |
} else { | |
echo wp_kses_post( wpautop( wptexturize( $message ) ) ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment