ฉันต้องการซ่อนที่อยู่สำหรับจัดส่งหากป้ายกำกับสำหรับจัดส่งมีชื่อว่า "รับสินค้าที่ Rockefeller Store" (แต่จะแสดงสำหรับวิธีการรับสินค้าแบบอื่นๆ)
มีรหัสมากเกินไป เช่น " local_pickup:3" เพื่อให้ฉันกรองผ่าน ฉันเปิดใช้งานที่อยู่สำหรับจัดส่งให้แสดงใน emails/email-addresses.php แม้ว่าจะเป็นวิธีการรับในพื้นที่ก็ตาม
การลองรหัสของฉัน:
<?php
/**
* Email Addresses
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/email-addresses.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\\Templates\\Emails
* @version 3.9.0
*/
if ( ! defined( \'ABSPATH\' ) ) {
exit;
}
$text_align = is_rtl() ? \'right\' : \'left\';
$address = $order->get_formatted_billing_address();
$shipping = $order->get_formatted_shipping_address();
?><table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top; margin-bottom: 40px; padding:0;" border="0">
<tr>
<td style="text-align:<?php echo esc_attr( $text_align ); ?>; font-family: \'Helvetica Neue\', Helvetica, Roboto, Arial, sans-serif; border:0; padding:0;" valign="top" width="50%">
<h2><?php esc_html_e( \'Billing address\', \'woocommerce\' ); ?></h2>
<address class="address">
<?php echo wp_kses_post( $address ? $address : esc_html__( \'N/A\', \'woocommerce\' ) ); ?>
<?php if ( $order->get_billing_phone() ) : ?>
<br/><?php echo wc_make_phone_clickable( $order->get_billing_phone() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_email() ) : ?>
<br/><?php echo esc_html( $order->get_billing_email() ); ?>
<?php endif; ?>
</address>
</td>
<?php if ( $shipping ) : ?>
<td style="text-align:<?php echo esc_attr( $text_align ); ?>; font-family: \'Helvetica Neue\', Helvetica, Roboto, Arial, sans-serif; padding:0;" valign="top" width="50%">
<h2><?php esc_html_e( \'Shipping address\', \'woocommerce\' ); ?></h2>
<address class="address"><?php echo wp_kses_post( $shipping ); ?></address>
</td>
<?php endif; ?>
</tr>
</table>
ฉันต้องการเปิดใช้สิ่งนี้เนื่องจากวิธีรับสินค้าอื่นๆ บางวิธีของเราจำเป็นต้องใช้ และฉันกำลังพยายามให้มีเพื่อที่ว่าหากเป็นเพียง "รับสินค้าที่ Rockefeller Store" ก็ควรจะซ่อนที่อยู่สำหรับจัดส่งในอีเมล WooCommerce คำสั่งซื้อใหม่
ฉันจะกรองสิ่งนี้ตามที่อยู่ของมันได้อย่างไร ป้ายข้อความตามภาพ?
ไม่จำเป็นต้องแก้ไขไฟล์เทมเพลต เนื่องจากสามารถทำได้ผ่าน hooks คำตอบนี้ประกอบด้วย 2 ส่วน:
1) ส่วนแรกจะต้องดำเนินการเพียงครั้งเดียวและทำหน้าที่เป็นข้อมูลการแก้ไขข้อบกพร่อง ข้อความต่อไปนี้ จะปรากฏในจดหมายสั่งซื้อใหม่
ข้อมูล DEBUG, วิธีการจัดส่ง id = THE_SHIPPING_METHOD_ID
ตอนที่ 1:
// DEBUG information
function action_woocommerce_email_before_order_table( $order, $sent_to_admin, $plain_text, $email ) {
// Only for \'new order\'
if ( $email->id == \'new_order\' ) {
// Get shipping methods
foreach ( $order->get_shipping_methods() as $shipping_method ) {
// Get method ID
$shipping_method_id = $shipping_method->get_method_id();
// Output
echo \'<p>DEBUG INFORMATION, shipping method id = \' . $shipping_method_id . \'</p>\';
}
}
}
add_action( \'woocommerce_email_before_order_table\', \'action_woocommerce_email_before_order_table\', 10, 4 );
หมายเหตุ: หลังจากทราบข้อมูลที่ถูกต้องแล้ว คุณไม่ควรใช้ส่วนที่ 1 อีกต่อไป
2) จากนั้นคุณสามารถใช้ส่วนที่ 2 ของคำตอบของฉันได้
โดยที่คุณต้องแทนที่REPLACE_THIS_WITH_THE_SHIPPING_METHOD_ID
ด้วยTHE_SHIPPING_METHOD_ID< /code> ข้อมูลนั้นมาจากส่วนแรกของคำตอบของฉัน
ส่วนที่ 2:
< code>// การตั้งค่า email_is เป็นตัวแปรส่วนกลาง
function action_woocommerce_email_before_order_table( $order, $sent_to_admin, $plain_text, $email ) {
$GLOBALS[\'email_id_str\'] = $email- >id;
}
add_action( \'woocommerce_email_before_order_table\', \'action_woocommerce_email_before_order_table\', 10, 4 );
function filter_woocommerce_order_hide_shipping_address( $shipping_method_id, $order ) {
// รับ ID อีเมลตัวแปรส่วนกลาง\ n $refNameGlobalsVar = $GLOBALS;
$email_id = isset( $refNameGlobalsVar[\'email_id_str\'] ) ? $refNameGlobalsVar[\'email_id_str\'] : \'\';
// เฉพาะสำหรับ \'คำสั่งใหม่\'
ถ้า ( $email_id == \'new_order\' ) {
// แทนที่ ส่วนที่ 2 ในอาร์เรย์ที่มี \'shipping_method_id\' จาก DEBUG INFORMATION
$shipping_method_id = array( \'local_pickup\', \'REPLACE_THIS_WITH_THE_SHIPPING_METHOD_ID\' );
} else {
// ค่าเริ่มต้น
$shipping_method_id = array( \'local_pickup\' );
}
ส่งคืน $shipping_method_id;
}
add_filter( \'woocommerce_order_hide_shipping_address\', \'filter_woocommerce_order_hide_shipping_address\', 10, 2 );
หมายเหตุ: เนื่องจากไม่ทราบรหัสอีเมลในส่วนที่ 2 ของคำตอบ จึงใช้วิธีแก้ไขปัญหานี้ โปรดดูที่: https://stackoverflow.com/a/ 43574008/11987538
$shipping_local_pickup = false;
if ( $items_totals = $order->get_order_item_totals() ) {
foreach ( $items_totals as $items_total ) {
if ( $items_total[\'value\'] == \'Pick Up at Rockefeller Store\' && !$shipping_local_pickup ) $shipping_local_pickup = true;
}
}
การเพิ่มสิ่งนี้ในเทมเพลตของฉันได้ผล จากนั้นตั้งค่าบรรทัด 48 เป็น !$shipping_local_pickup
วิธีนี้ช่วยให้ฉันสามารถเลือกวลี "รับสินค้าที่ Rockefeller Store" ที่ใช้ในตารางและไม่แสดงที่อยู่สำหรับจัดส่งหากมีอยู่< /p>
รับและแก้ไขคำตอบจากซ่อนที่อยู่สำหรับจัดส่งในการรับสินค้าในพื้นที่ในการแจ้งเตือนทางอีเมลของ WooCommerce
กำลังหาวิธีซ่อนที่อยู่และฟิลด์อื่นๆ สำหรับวิธีรับสินค้าในพื้นที่ ฉันเห็นข้อความตอบกลับนี้ https://wpsimplehacks.com/how-to-hide-woocommerce- checkout-fields-when-local-pickup-is-selected/
นี่คือรหัสและใช้งานได้สำหรับฉัน:
{- code-1}
หากคุณต้องการซ่อน "ส่งไปยังที่อยู่อื่น" ในหน้าชำระเงิน ลองทำดังนี้:
{ -code-2}
เครดิตทั้งหมดเป็นของ Janek T ไม่พบโปรไฟล์ของเขาที่ stackoverflow
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.