HEX
Server: Apache/2.4.57 (Debian)
System: Linux web-server-k8s-e92jnr3j-6f99bff6b6-rp2wg 6.1.0-22-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.94-1 (2024-06-21) x86_64
User: apache (48)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/sites/1250.info/wp-content/themes/savoy/includes/woocommerce/admin/admin-product-data.php
<?php
/*
 *	WooCommerce admin: Product data
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class NM_Product_Data {
    
    /*
	 * Constructor
	 */
	public function __construct() {
        // Attributes: Add setting
		add_action( 'woocommerce_after_product_attribute_settings', array( $this, 'product_attribute_settings' ), 1, 2 );
        
        // Attributes: Save setting
        add_action( 'woocommerce_update_product', array( $this, 'product_attribute_settings_save' ) );
        //Alt: add_action( 'wp_ajax_woocommerce_save_attributes', array( $this, 'ajax_product_attribute_settings_save' ), 0 ); // AJAX hook from "../woocommerce/includes/class-wc-ajax.php"
	}
    
    
    /*
     * Product data - Attribute settings: Include custom setting
     */
    public function product_attribute_settings( $attribute, $i ) {
        global $post, $nm_globals;
        
        // Make sure the attribute is for a variation
        if ( isset( $attribute['variation'] ) && $attribute['variation'] == true ) {
            $attr = nm_woocommerce_get_taxonomy_attribute( $attribute['name'] ); // "nm_woocommerce_get_taxonomy_attribute()" is in "../savoy/includes/woocommerce/woocommerce-attribute-functions.php"
            $custom_attr_types = array_keys( $nm_globals['pa_variation_controls'] );
            
            if ( in_array( $attr->attribute_type, $custom_attr_types ) ) {
                // Get product ID
                if ( $post ) {
                    $product_id = $post->ID;
                } else if ( isset( $_POST['post_id'] ) ) {
                    $product_id = absint( wp_unslash( $_POST['post_id'] ) ); // $post is unavailbale when saving via AJAX - see "save_attributes()" in "../woocommerce/includes/class-wc-ajax.php"
                } else {
                    return;
                }

                // Get saved product meta
                $saved_data = get_post_meta( $product_id, 'nm_attribute_catalog_visibility', true );
                $checked = ( $saved_data && isset( $saved_data[$attribute['name']] ) ) ? true : false;
                ?>
                <tr>
                    <td>
                        <label><input type="checkbox" class="checkbox" <?php checked( $checked, true ); ?> name="nm_attribute_catalog_visibility[<?php echo esc_attr( $attribute['name'] ); ?>]" value="1" /> <?php esc_html_e( 'Show in product catalog', 'nm-framework-admin' ); ?></label>
                    </td>
                </tr>
                <?php
            }
        }
    }
    
    
    /*
     * Product data - Attribute settings: Save custom setting
     */
    public function product_attribute_settings_save( $product_id = null ) {
        $saved_data = null;
        
        // AJAX save
        if ( isset( $_POST['data'], $_POST['post_id'] ) ) {
            // Based on "save_attributes()" in "../woocommerce/includes/class-wc-ajax.php":
            
            check_ajax_referer( 'save-attributes', 'security' );
            
            $product_id = absint( wp_unslash( $_POST['post_id'] ) );
            parse_str( wp_unslash( $_POST['data'] ), $data );
            
            if ( isset( $data['nm_attribute_catalog_visibility'] ) ) {
                $saved_data = $data['nm_attribute_catalog_visibility'];
            }
            
            if ( $saved_data ) {
                update_post_meta( $product_id, 'nm_attribute_catalog_visibility', $saved_data );
            } else {
                delete_post_meta( $product_id, 'nm_attribute_catalog_visibility' );
            }
        }
        // Static save
        else if ( ! wp_doing_ajax() ) { // Make sure this isn't an AJAX request (like when saving Variations via AJAX)
            if ( isset( $_POST['nm_attribute_catalog_visibility'] ) ) {
                $saved_data = $_POST['nm_attribute_catalog_visibility'];
            }
            
            if ( $saved_data ) {
                update_post_meta( $product_id, 'nm_attribute_catalog_visibility', $saved_data );
            } else {
                delete_post_meta( $product_id, 'nm_attribute_catalog_visibility' );
            }
        }
    }

}

$NM_Product_Data = new NM_Product_Data();