Files
krolewskie-miody.pl/wp-content/plugins/woocommerce-paczkomaty-inpost/class/class-abstract-shipment-field-checkbox.php
2026-04-28 15:13:50 +02:00

111 lines
2.3 KiB
PHP

<?php
/**
* End of Week Collecetion.
*
* @package PaczkomatyInpost
*/
/**
* Handles abstract field functionality on shipment.
*/
abstract class WPDesk_Paczkomaty_Abstract_Shipment_Field_Checkbox implements WPDesk_Paczkomaty_Shipment_Field {
use WPDesk_Flexible_Shipping_Shipment_Paczkomaty_Filtered_Meta;
/**
* .
*
* @var string
*/
protected $field_name;
/**
* .
*
* @var string
*/
protected $meta_name;
/**
* Shipment.
*
* @var WPDesk_Flexible_Shipping_Shipment_Paczkomaty
*/
protected $shipment;
/**
* .
*
* @param string $field_name .
* @param string $meta_name .
* @param WPDesk_Flexible_Shipping_Shipment_Paczkomaty $shipment .
*/
public function __construct( $field_name, $meta_name, $shipment ) {
$this->field_name = $field_name;
$this->meta_name = $meta_name;
$this->shipment = $shipment;
}
/**
* Handle checkout.
*
* @param array $fs_method Flexible Shipping method settings.
* @param array $package WooCommerce package.
*/
public function handle_checkout( array $fs_method, array $package ) {
if ( isset( $fs_method[ $this->field_name ] )
&& '1' === $fs_method[ $this->field_name ]
) {
$meta_value = 1;
} else {
$meta_value = 0;
}
$this->shipment->set_meta(
$this->meta_name,
$this->get_meta_filtered_value(
$this->meta_name,
$meta_value,
$fs_method,
$package,
$this->shipment->get_order()
)
);
}
/**
* Prepare matebox field values.
*
* @param array $values .
*
* @return array
*/
public function prepare_metabox_field_values( array $values ) {
$values[ $this->field_name ] = $this->shipment->get_meta( $this->meta_name, '0' );
return $values;
}
/**
* Save data from metabox.
*
* @param array $ajax_data .
*/
public function save_ajax_data( array $ajax_data ) {
if ( isset( $ajax_data[ $this->field_name ] ) ) {
$this->shipment->set_meta( $this->meta_name, sanitize_text_field( $ajax_data[ $this->field_name ] ) );
} else {
$this->shipment->set_meta( $this->meta_name, '0' );
}
}
/**
* .
*
* @param stdClass $shipment_data .
*
* @return stdClass
* @throws WPDesk_Paczkomaty_ShipX_Exception .
*/
abstract public function modify_shipment_data( $shipment_data );
}