Кемеровские программисты php общаются здесь
Anonymous
Попытка использовать поле формы Ajax woocommerce, но в журнале консоли возникает нулевая ошибка
Сообщение
Anonymous » 12 окт 2024, 16:08
Я пытаюсь передать значение поля формы Woocommerce через ajax в WC_Session.
Частично основано на учебнике "Создание собственного метода доставки для WooCommerce" и "Динамическая плата за доставку на основе пользовательских переключателей в Woocommerce". " ветка ответов, вот фрагмент попытки кода:
Код: Выделить всё
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
function my_custom_shipping_method() {
if ( ! class_exists( 'MY_Custome_Shipping_Method' ) ) {
class my_custom_Shipping_Method extends WC_Shipping_Method {
public function __construct() {
$this->id = 'my_custome_shipping_method';
$this->method_title = __( 'My Customize Shipping','my_custome_shipping_method' );
$this->method_description = __( 'Custom Shipping Method for my custome shipping method', 'my_custome_shipping_method' );
.......
}
.......
//other shipping method code skipped
.......
public function calculate_shipping( $package = array() ) {
.......
$string = json_encode($result);
$decodedArray = json_decode($result,true);
$kekei = $decodedArray['msg'];
$balbal = array();
foreach($kekei as $goods=> $g_values) {
$balbal[$g_key['shipping_code'] ] = $g_values['shipping_name'];;
}
$janggal = (array)$balbal;
WC()->session->set('janel_seesion', $balbal);
.......
}
}
}
}
}
add_action( 'woocommerce_shipping_init', 'my_custome_shipping_method' );
function add_mycustome_shipping_method( $methods ) {
$methods[] = 'My_Custome_Shipping_Method';
return $methods;
}
add_filter( 'woocommerce_shipping_methods', 'add_mycustome_shipping_method' );
// Enabling delivery options for a specific defined shipping method
function targeted_shipping_method(){
// HERE below define the shipping method Id that enable the custom delivery options
//return 'local_pickup:5';
return 'my_custome_shipping_method';
}
// Customizing Woocommerce checkout radio form field
add_action( 'woocommerce_form_field_radio', 'custom_form_field_radio', 20, 4 );
function custom_form_field_radio( $field, $key, $args, $value ) {
if ( ! empty( $args['options'] ) && is_checkout() ) {
$field = str_replace( '
Подробнее здесь: [url]https://stackoverflow.com/questions/57751221/trying-to-ajax-woocommerce-form-field-but-have-null-error-at-console-log[/url]
1728738484
Anonymous
Я пытаюсь передать значение поля формы Woocommerce через ajax в WC_Session. Частично основано на учебнике "Создание собственного метода доставки для WooCommerce" и "Динамическая плата за доставку на основе пользовательских переключателей в Woocommerce". " ветка ответов, вот фрагмент попытки кода: [code]if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { function my_custom_shipping_method() { if ( ! class_exists( 'MY_Custome_Shipping_Method' ) ) { class my_custom_Shipping_Method extends WC_Shipping_Method { public function __construct() { $this->id = 'my_custome_shipping_method'; $this->method_title = __( 'My Customize Shipping','my_custome_shipping_method' ); $this->method_description = __( 'Custom Shipping Method for my custome shipping method', 'my_custome_shipping_method' ); ....... } ....... //other shipping method code skipped ....... public function calculate_shipping( $package = array() ) { ....... $string = json_encode($result); $decodedArray = json_decode($result,true); $kekei = $decodedArray['msg']; $balbal = array(); foreach($kekei as $goods=> $g_values) { $balbal[$g_key['shipping_code'] ] = $g_values['shipping_name'];; } $janggal = (array)$balbal; WC()->session->set('janel_seesion', $balbal); ....... } } } } } add_action( 'woocommerce_shipping_init', 'my_custome_shipping_method' ); function add_mycustome_shipping_method( $methods ) { $methods[] = 'My_Custome_Shipping_Method'; return $methods; } add_filter( 'woocommerce_shipping_methods', 'add_mycustome_shipping_method' ); // Enabling delivery options for a specific defined shipping method function targeted_shipping_method(){ // HERE below define the shipping method Id that enable the custom delivery options //return 'local_pickup:5'; return 'my_custome_shipping_method'; } // Customizing Woocommerce checkout radio form field add_action( 'woocommerce_form_field_radio', 'custom_form_field_radio', 20, 4 ); function custom_form_field_radio( $field, $key, $args, $value ) { if ( ! empty( $args['options'] ) && is_checkout() ) { $field = str_replace( ' Подробнее здесь: [url]https://stackoverflow.com/questions/57751221/trying-to-ajax-woocommerce-form-field-but-have-null-error-at-console-log[/url]