File: /var/www/html/test01.amberconcept/wp-content/themes/zeen-child/functions.php20210804a
<?php
/**
* Zeen Child Theme functions and definitions.
*/
function zeen_child_enqueue_styles() {
wp_enqueue_style( 'zeen-child-style' , get_stylesheet_directory_uri() . '/style.css', array( 'zeen-style' ), ZEEN_VERSION );
}
add_action( 'wp_enqueue_scripts', 'zeen_child_enqueue_styles' );
/**--Spreads min&max page*/
add_action('wp_footer', 'settap_number_field', 99);
function settap_number_field() {
if(is_single()) {
?>
<script type="text/javascript">
(function($) {
$("#msspreads, #mmspreads, #mlspreads").attr({
"max" : 45,
"min" : 15
});
$("#fsspreads, #fmspreads, #flspreads").attr({
"max" : 40,
"min" : 10
});
})(jQuery, window, document)
</script>
<?php
}
}
/**--*/
// Declare WooCommerce support.
add_theme_support( 'woocommerce', array(
'thumbnail_image_width' => 200,
'gallery_thumbnail_image_width' => 100,
'single_image_width' => 500,
) );
//
//from::https://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column
// For displaying in columns.
add_filter( 'manage_edit-shop_order_columns', 'set_custom_edit_shop_order_columns' );
add_filter( 'manage_edit-shop_order_columns', 'set_custom_edit_shop_order_columns2' );
add_filter( 'manage_edit-shop_order_columns', 'set_custom_edit_shop_order_columns3' );
function set_custom_edit_shop_order_columns($columns) {
$columns['Product_cost'] = __( 'Product_cost', 'https://wp.amberconcept.com/' );
return $columns;
}
function set_custom_edit_shop_order_columns2($columns) {
$columns['Shipping_cost'] = __( 'Shipping_cost', 'https://wp.amberconcept.com/' );
return $columns;
}
function set_custom_edit_shop_order_columns3($columns) {
$columns['Awb_no'] = __( 'Awb_no', 'https://wp.amberconcept.com/' );
return $columns;
}
// Add the data to the custom columns for the order post type:
add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_column', 10, 2 );
add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_column2', 10, 2 );
add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_column3', 10, 2 );
function custom_shop_order_column( $column, $post_id ) {
switch ( $column ) {
case 'Product_cost' :
echo esc_html( get_post_meta( $post_id, 'Product_cost', true ) );
break;
}
}
function custom_shop_order_column2( $column, $post_id ) {
switch ( $column ) {
case 'Shipping_cost' :
echo esc_html( get_post_meta( $post_id, 'Shipping_cost', true ) );
break;
}
}
function custom_shop_order_column3( $column, $post_id ) {
switch ( $column ) {
case 'Awb_no' :
echo esc_html( get_post_meta( $post_id, 'Awb_no', true ) );
break;
}
}
// For display and saving in order details page.
add_action( 'add_meta_boxes', 'add_shop_order_meta_box2' );
function add_shop_order_meta_box2() {
add_meta_box(
'Awb_no',
__( 'Awb_no', 'https://wp.amberconcept.com/' ),
'shop_order_display_callback2',
'shop_order'
);
}
add_action( 'add_meta_boxes', 'add_shop_order_meta_box3' );
function add_shop_order_meta_box3() {
add_meta_box(
'Product_cost',
__( 'Product_cost', 'https://wp.amberconcept.com/' ),
'shop_order_display_callback3',
'shop_order'
);
}
add_action( 'add_meta_boxes', 'add_shop_order_meta_box4' );
function add_shop_order_meta_box4() {
add_meta_box(
'Shipping_cost',
__( 'Shipping_cost', 'https://wp.amberconcept.com/' ),
'shop_order_display_callback4',
'shop_order'
);
}
function shop_order_display_callback2( $post ) {
$value = get_post_meta( $post->ID, 'Awb_no', true );
echo '<input type="text" style="width:100%" id="Awb_no" name="Awb_no" value="'.esc_attr( $value ).'">';
}
function shop_order_display_callback3( $post ) {
$value = get_post_meta( $post->ID, 'Product_cost', true );
echo '<input type="text" style="width:100%" id="Product_cost" name="Product_cost" value="'.esc_attr( $value ).'">';
}
function shop_order_display_callback4( $post ) {
$value = get_post_meta( $post->ID, 'Shipping_cost', true );
echo '<input type="text" style="width:100%" id="Shipping_cost" name="Shipping_cost" value="'.esc_attr( $value ).'">';
}
// For saving.
function save_shop_order_meta_box_data( $post_id ) {
global $wpdb;
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'shop_order' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_shop_order', $post_id ) ) {
return;
}
}
// check if this is an admin order page
if(!is_admin()){
return;
}
//handling Product_cost
if (isset( $_POST['Product_cost'])){
update_post_meta( $post_id, 'Product_cost', sanitize_text_field( $_POST['Product_cost'] ));
}
//handling Shipping_cost
if (isset( $_POST['Shipping_cost'])){
update_post_meta( $post_id, 'Shipping_cost', sanitize_text_field( $_POST['Shipping_cost'] ));
}
//handling Awb_no
if (isset( $_POST['Awb_no'])){
update_post_meta( $post_id, 'Awb_no', sanitize_text_field( $_POST['Awb_no'] ));
}
}
add_action( 'save_post', 'save_shop_order_meta_box_data',10,1);