嗨,我一直在摸不着头脑,想弄清楚为什么这些脚本中至少有一个对我不起作用。我试过他们被注销但仍然一无所获。任何帮助找出问题所在的帮助将不胜感激。
我正在尝试将此字符串传递给 Woocommerce 单页结帐页面。我没有使用购物车。
我已经创建了一份文档,其中包含我最终申请中要采取的所有步骤。它还包括我收集和尝试的所有片段。
https://docs.google.com/document/d/153elfEFpoAKOwE_PLErz4B4WM9qMX6b_G7Eeja4m-n8/edit?usp=sharing
片段 1 和 2 什么都不做。片段 4 产生严重错误。
这是我的字符串 https://sizzlinghotmarriage.com/dont-give-up-on-love-checkout/?add-to-cart=24631&quantity=1,fname=[1886 sanitize_url=1],lname=[1887 sanitize_url=1] ,email=[1820 sanitize_url=1],phone=[1821 sanitize_url=1],address1=[1822 sanitize_url=1],address2=[1888 sanitize_url=1],city=[1823 sanitize_url=1],state=[1824 sanitize_url=1],zip=[1825 sanitize_url=1],country=[1826 sanitize_url=1]
这是片段 1 /**
// 连接到 WooCommerce 结帐字段。 add_filter( 'woocommerce_checkout_fields' , 'ts_prefill_checkout_fields');
函数 ts_prefill_checkout_fields ( $checkout_fields ) {
/**
* Query string fields to populate in checkout,
*
* Ex.
* 'fname' => is query parameter name,
* 'billing_first_name' => matching field of checkout
*
* You can add other fields in the same way
*/
$query_fields = array(
'fname' => 'billing_first_name',
'lname' => 'billing_last_name',
'email' => 'billing_email',
'phone' => 'billing_phone',
'address1' => 'billing_address1',
'address2' => 'billing_address2',
'city' => 'billing_city',
'state' => 'billing_state',
'zip' => 'billing_postcode',
'country' => 'billing_country',
);
// We will loop the above array to check if the field exists in URL or not.
// If it exists we will add it to the checkout field's default value
foreach ( $query_fields as $field_slug => $match_field ) {
// Check if it is in URL or not, An not empty.
if ( isset( $_GET[ $field_slug ] ) && ! empty( $_GET[ $field_slug ] ) ) {
// Sanitize the value and store it in a variable.
$field_value = sanitize_text_field( $_GET[ $field_slug ] );
// Check if match field exists in checkout form or not.
if( isset( $checkout_fields['billing'][ $match_field ] ) ){
// Assign the pre-fill value to checkout field
$checkout_fields['billing'][ $match_field ]['default'] = $field_value;
}
}
}
// Return the fields
return $checkout_fields;
}
我已经根据我的参数调整了每个脚本,但每个脚本都无法预填充 woocommerce 结帐。