PHP, WordPress

EdiSES – Prodotti Disabilitati

SELECT DISTINCT cpe.entity_id, cpe.sku, cpev_name.value AS product_name
FROM catalog_product_entity AS cpe
JOIN catalog_product_entity_int AS cpei_visibility ON cpe.entity_id = cpei_visibility.entity_id
JOIN catalog_product_entity_int AS cpei_status ON cpe.entity_id = cpei_status.entity_id
JOIN cataloginventory_stock_item AS csi ON cpe.entity_id = csi.product_id
JOIN catalog_product_entity_varchar AS cpev_name ON cpe.entity_id = cpev_name.entity_id
WHERE cpei_status.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'status' AND entity_type_id = 4)
AND cpei_status.value = 1 /* Stato abilitato */
AND cpei_visibility.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'visibility' AND entity_type_id = 4)
AND cpei_visibility.value = 2 /* Visibilità solo catalogo */
AND csi.manage_stock = 1 /* Gestione inventario non disponibile */
AND cpev_name.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 4);

fare riferimento allo script prodotti-disabilitati.php
// TODO
abilitare eliminazione record _rivolgiti_libreria se già esistente

PHP

Dea Salus – WooCommerce Print Invoice & Delivery Note/Templates

<?php
/**
 * Print order content. Copy this file to your themes
 * directory /woocommerce/print-order to customize it.
 *
 * @package WooCommerce Print Invoice & Delivery Note/Templates
 */

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

	<div class="order-branding">
		<div class="company-logo" style="display:inline-block;width:50%;">
			<?php
			if ( wcdn_get_company_logo_id() ) :
				?>
				<?php wcdn_company_logo(); ?><?php endif; ?>
				
		</div>

		<div class="order-notes" style="display:inline-block;margin:0px;">
		<?php if ( wcdn_has_customer_notes( $order ) ) : ?>
			<h4><?php esc_attr_e( 'Customer Note', 'woocommerce-delivery-notes' ); ?></h4>
			<?php wcdn_customer_notes( $order ); ?>
		<?php endif; ?>

		<?php do_action( 'wcdn_after_notes', $order ); ?>
	</div><!-- .order-notes -->

		<div class="company-info">
			<?php
			if ( ! wcdn_get_company_logo_id() ) :
				?>
				<h1 class="company-name"><?php wcdn_company_name(); ?></h1><?php endif; ?>
			<div class="company-address"><?php wcdn_company_info(); ?></div>
		</div>

		<?php do_action( 'wcdn_after_branding', $order ); ?>
	</div><!-- .order-branding -->

	<div class="order-addresses">
		<div class="billing-address">
			<h3><?php esc_attr_e( 'Billing Address', 'woocommerce-delivery-notes' ); ?></h3>
			<address>

				<?php
				if ( ! $order->get_formatted_billing_address() ) {
					esc_attr_e( 'N/A', 'woocommerce-delivery-notes' );
				} else {
					echo wp_kses_post( apply_filters( 'wcdn_address_billing', $order->get_formatted_billing_address(), $order ) );
				}
				?>

			</address>
		</div>

		<div class="shipping-address">						
			<h3><?php esc_attr_e( 'Shipping Address', 'woocommerce-delivery-notes' ); ?></h3>
			<address>

				<?php
				if ( ! $order->get_formatted_shipping_address() ) {
					esc_attr_e( 'N/A', 'woocommerce-delivery-notes' );
				} else {
					echo wp_kses_post( apply_filters( 'wcdn_address_shipping', $order->get_formatted_shipping_address(), $order ) );
				}
				?>

			</address>
		</div>

		<?php do_action( 'wcdn_after_addresses', $order ); ?>
	</div><!-- .order-addresses -->


	<div class="order-info">
		<h2><?php wcdn_document_title(); ?></h2>

		<ul class="info-list">
			<?php
			$fields = apply_filters( 'wcdn_order_info_fields', wcdn_get_order_info( $order ), $order );
			?>
			<?php foreach ( $fields as $field ) : ?>
				<li>
					<strong><?php echo wp_kses_post( apply_filters( 'wcdn_order_info_name', $field['label'], $field ) ); ?></strong>
					<span><?php echo wp_kses_post( apply_filters( 'wcdn_order_info_content', $field['value'], $field ) ); ?></span>
				</li>
			<?php endforeach; ?>

					<?php
			$spedizione = $order->get_shipping_method();
			
			if ($spedizione == 'Ritiro in Negozio (Padova, Via Guizza 215)'){
			?>
			<li>
			<strong>Spedizione</strong>
			<span style="font-weight:bold;">RITIRO IN NEGOZIO</span>
			</li>
			<?php
			}
			?>
			
			<?php
			$spedizione = $order->get_shipping_method();
			
			if ($spedizione == 'Ritiro in Negozio (Schiavonia - C/O Sanitaria Ospedale)'){
			?>
			<li>
			<strong>Spedizione</strong>
			<span style="font-weight:bold;">RITIRO SCHIAVONIA</span>
			</li>
			<?php
			}
			?>

			<?php
			$payment_method = $order->get_payment_method_title();
			
			if ($payment_method === 'Pay Later'){
			?>
			<li>
			<strong>Pagamento:</strong>
			<span style="font-weight:bold;">PayPal in 3 rate</span>
			</li>
			<?php
			}
			?>

				<?php
				// Ottenere lo stato della richiesta di fattura
				$fattura_ricevuta = get_post_meta( $order->get_id(), 'fattura_ricevuta', true );

				// Verificare se è stata richiesta la fattura
				if ( $fattura_ricevuta && $fattura_ricevuta === 'SI' ) :
					?>
					<li>
						<strong><?php esc_attr_e( 'Richiesta Fattura', 'woocommerce-delivery-notes' ); ?></strong>
						<span style="font-weight:bold;"><?php esc_html_e( 'Sì', 'woocommerce-delivery-notes' ); ?></span>
					</li>
				<?php endif; ?>


				<?php
				// Ottenere lo stato della richiesta di pacco regalo
				$pacco_regalo = get_post_meta( $order->get_id(), 'pacco_regalo', true );

				// Verificare se è stata richiesta la confezione regalo
				if ( $pacco_regalo && $pacco_regalo === 'Sì' ) :
					?>
					<li>
						<strong><?php esc_attr_e( 'Confezione Regalo', 'woocommerce-delivery-notes' ); ?></strong>
						<span style="font-weight:bold;"><?php esc_html_e( 'Sì', 'woocommerce-delivery-notes' ); ?></span>
					</li>
				<?php endif; ?>


			
		</ul>

		<?php do_action( 'wcdn_after_info', $order ); ?>
	</div><!-- .order-info -->


	<div class="order-items">
		<table>
			<thead>
				<tr>
					<th class="head-name"><span><?php esc_attr_e( 'Product', 'woocommerce-delivery-notes' ); ?></span></th>
					<th class="head-item-price"><span><?php esc_attr_e( 'Price', 'woocommerce-delivery-notes' ); ?></span></th>
					<th class="head-quantity"><span><?php esc_attr_e( 'Quantity', 'woocommerce-delivery-notes' ); ?></span></th>
					<th class="head-price"><span><?php esc_attr_e( 'Total', 'woocommerce-delivery-notes' ); ?></span></th>
				</tr>
			</thead>

			<tbody>
				<?php

				if ( count( $order->get_items() ) > 0 ) :
					?>
					<?php foreach ( $order->get_items() as $item_id => $item ) : ?>

						<?php

						$product = apply_filters( 'wcdn_order_item_product', $item->get_product(), $item );
						if ( ! $product ) {
							continue;
						}
						if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
							$item_meta = new WC_Order_Item_Product( $item['item_meta'], $product );
						} else {
							$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $product );
						}
						?>
						<tr>
							<td class="product-name">
								<?php do_action( 'wcdn_order_item_before', $product, $order, $item ); ?>
								<span class="name">
								<?php

								$addon_name  = $item->get_meta( '_wc_pao_addon_name', true );
								$addon_value = $item->get_meta( '_wc_pao_addon_value', true );
								$is_addon    = ! empty( $addon_value );

								if ( $is_addon ) { // Displaying options of product addon.
									$addon_html = '<div class="wc-pao-order-item-name">' . esc_html( $addon_name ) . '</div><div class="wc-pao-order-item-value">' . esc_html( $addon_value ) . '</div></div>';

									echo wp_kses_post( $addon_html );
								} else {

									$product_id   = $item['product_id'];
									$prod_name    = get_post( $product_id );
									$product_name = $prod_name->post_title;

									echo wp_kses_post( apply_filters( 'wcdn_order_item_name', $product_name, $item ) );
									?>
									</span>

									<?php
									$item_meta_fields = apply_filters( 'wcdn_product_meta_data', $item['item_meta'], $item );

									$product_addons            = array();
									$woocommerce_product_addon = 'woocommerce-product-addons/woocommerce-product-addons.php';
									if ( in_array( $woocommerce_product_addon, apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ), true ) ) {
										$product_id     = $item['product_id'];
										$product_addons = WC_Product_Addons_Helper::get_product_addons( $product_id );
									}
									if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
										if ( isset( $item['variation_id'] ) && 0 !== $item['variation_id'] ) {
											$variation = wc_get_product( $item['product_id'] );
											foreach ( $item_meta_fields as $key => $value ) {
												if ( ! ( 0 === strpos( $key, '_' ) ) ) {
													if ( is_array( $value ) ) {
														continue;
													}
													$term_wp        = get_term_by( 'slug', $value, $key );
													$attribute_name = wc_attribute_label( $key, $variation );
													if ( ! empty( $product_addons ) ) {
														foreach ( $product_addons as $addon ) {
															if ( 'file_upload' === $addon['type'] ) {
																if ( $key === $addon['name'] ) {
																	$value = wp_basename( $value );
																}
															}
														}
													}
													if ( isset( $term_wp->name ) ) {
														echo '<br>' . wp_kses_post( $attribute_name . ':' . $term_wp->name );
													} else {
														echo '<br>' . wp_kses_post( $attribute_name . ':' . $value );
													}
												}
											}
										} else {
											foreach ( $item_meta_fields as $key => $value ) {
												if ( ! ( 0 === strpos( $key, '_' ) ) ) {
													if ( is_array( $value ) ) {
														continue;
													}
													if ( ! empty( $product_addons ) ) {
														foreach ( $product_addons as $addon ) {
															if ( 'file_upload' === $addon['type'] ) {
																if ( $key === $addon['name'] ) {
																	$value = wp_basename( $value );
																}
															}
														}
													}
													echo '<br>' . wp_kses_post( $key . ':' . $value );
												}
											}
										}
									} else {
										$item_meta_new = new WC_Order_Item_Meta( $item_meta_fields, $product );
										$item_meta_new->display();

									}
									?>
									<br>
									<dl class="extras">
										<?php if ( $product && $product->exists() && $product->is_downloadable() && $order->is_download_permitted() ) : ?>

											<dt><?php esc_attr_e( 'Download:', 'woocommerce-delivery-notes' ); ?></dt>
											<dd>
											<?php
											// translators: files count.
											printf( esc_attr__( '%s Files', 'woocommerce-delivery-notes' ), count( $item->get_item_downloads() ) );
											?>
											</dd>

										<?php endif; ?>

										<?php
										wcdn_print_extra_fields( $item );
										$fields = apply_filters( 'wcdn_order_item_fields', array(), $product, $order, $item );

										foreach ( $fields as $field ) :
											?>

											<dt><?php echo esc_html( $field['label'] ); ?></dt>
											<dd><?php echo esc_html( $field['value'] ); ?></dd>

										<?php endforeach; ?>
									</dl>
								<?php } ?>
								<?php do_action( 'wcdn_order_item_after', $product, $order, $item ); ?>
							</td>
							<td class="product-item-price">
								<span><?php echo wp_kses_post( wcdn_get_formatted_item_price( $order, $item ) ); ?></span>
							</td>
							<td class="product-quantity">
								<span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item['qty'], $item ) ); ?></span>
							</td>
							<td class="product-price">
								<span><?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?></span>
							</td>
						</tr>
					<?php endforeach; ?>
				<?php endif; ?>
			</tbody>

			<tfoot>
				<?php
				$totals_arr = $order->get_order_item_totals();
				if ( $totals_arr ) :

					foreach ( $totals_arr as $total ) :
						?>
						<tr>
							<td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td>
							<td class="total-item-price"></td>
							<?php if ( 'Total' === $total['label'] ) { ?>
							<td class="total-quantity"><?php echo wp_kses_post( $order->get_item_count() ); ?></td>
							<?php } else {  ?>
							<td class="total-quantity"></td>
							<?php } ?>
							<td class="total-price"><span><?php echo wp_kses_post( $total['value'] ); ?></span></td>
						</tr>
					<?php endforeach; ?>
				<?php endif; ?>
			</tfoot>
		</table>

		<?php do_action( 'wcdn_after_items', $order ); ?>
	</div><!-- .order-items -->

	<div class="order-thanks">
		<?php wcdn_personal_notes(); ?>

		<?php do_action( 'wcdn_after_thanks', $order ); ?>
	</div><!-- .order-thanks -->

	<div class="order-colophon">
		<div class="colophon-policies">
			<?php wcdn_policies_conditions(); ?>
		</div>

		<div class="colophon-imprint">
			<?php wcdn_imprint(); ?>
		</div>	

		<?php do_action( 'wcdn_after_colophon', $order ); ?>
	</div><!-- .order-colophon -->


PHP

Categorie – Descrizione HTML

Questo script va fatto girare dopo l’import delle categorie, si occupa di sistemare i tag html delle descrizioni senza far tirare 10000 porchi

<?php
// Includi il file wp-load.php per avere accesso alle funzioni di WordPress
require_once('wp-load.php');

// Ottieni tutte le categorie di WooCommerce
$args = array(
    'taxonomy'   => 'product_cat',
    'hide_empty' => false,
);
$product_categories = get_terms($args);

// Controlla se ci sono categorie
if (!empty($product_categories)) {
    foreach ($product_categories as $category) {
        if (!empty($category) && !is_wp_error($category)) {
            // Ottieni l'ID della categoria
            $category_id = $category->term_id;

            // Ottieni la descrizione della categoria
            $description = $category->description;

            // Processa la descrizione qui se necessario
            // Per esempio, potresti voler usare html_entity_decode() o una funzione simile
            // per assicurarti che i tag HTML siano interpretati correttamente
            $processed_description = html_entity_decode($description);

            // Aggiorna la descrizione della categoria con la versione elaborata
            wp_update_term($category_id, 'product_cat', array(
                'description' => $processed_description,
            ));
        }
    }

    echo 'Le descrizioni delle categorie sono state aggiornate con successo.';
} else {
    echo 'Non ci sono categorie da aggiornare.';
}
PHP, WordPress

CSV Attributi completi

<?php
// Connessione al database WooCommerce
$servername = "localhost";
$username = "fabio";
$password = "aaa";
$dbname = "ed_imp";
$conn = new mysqli($servername, $username, $password, $dbname);

// Verifica della connessione
if ($conn->connect_error) {
    die("Connessione fallita: " . $conn->connect_error);
}

function rimuoviAccenti($stringa) {
    $mappatura = array(
        'à' => 'a', 'è' => 'e', 'ì' => 'i', 'ò' => 'o', 'ù' => 'u',
        'À' => 'A', 'È' => 'E', 'Ì' => 'I', 'Ò' => 'O', 'Ù' => 'U',
        'á' => 'a', 'é' => 'e', 'í' => 'i', 'ó' => 'o', 'ú' => 'u',
        'Á' => 'A', 'É' => 'E', 'Í' => 'I', 'Ó' => 'O', 'Ú' => 'U',
        // Aggiungi altre mappature se necessario
    );

    return strtr($stringa, $mappatura);
}

// Normalizza i nomi delle colonne per risolvere i duplicati
function normalizzaNomeColonna($nome) {
    $nome = str_replace([' ', '-'], '_', $nome);
    $nome = rimuoviAccenti($nome);

    // Rinomina le colonne duplicate
    switch ($nome) {
        case 'numero_pagine':
            return 'numero_pagine2';
        case 'isbn':
            return 'isbn2';
        case 'sottotitolo':
            return 'sottotitolo2';
        case 'tag':
            return 'tag2';
        case 'codice_prodotto':
            return 'codice_prodotto2';
        case 'ricerca_ebook':
            return 'ricerca_ebook2';
        default:
            return $nome;
    }
}


// Modifica della prima query per includere sku_woocommerce_magento e MAGENTO_ID
$sql = "SELECT
            p.ID as id_prodotto,
            p.post_title as nome_prodotto,
            p.post_name as slug_prodotto,
            pm.meta_value as attributi_serializzati,
            sku_meta.meta_value as sku_woocommerce_magento,
            cpe.entity_id as MAGENTO_ID
        FROM
            ed2024_posts p
        JOIN
            ed2024_postmeta pm ON p.ID = pm.post_id
        LEFT JOIN
            ed2024_postmeta sku_meta ON p.ID = sku_meta.post_id AND sku_meta.meta_key = '_sku'
        LEFT JOIN
            catalog_product_entity cpe ON sku_meta.meta_value = cpe.sku
        WHERE
            p.post_type = 'product' AND pm.meta_key = '_product_attributes'";

$result = $conn->query($sql);

// Inizializza un array per tenere traccia di tutti i nomi degli attributi
$attributi_header = array('id_prodotto', 'nome_prodotto', 'slug_prodotto', 'MAGENTO_ID');
$attributi_rows = array();

// Elabora i risultati della prima query e costruisci l'array degli attributi
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $attributi = unserialize($row['attributi_serializzati']);
        $attributi_row = array(
            'id_prodotto' => $row['id_prodotto'],
            'nome_prodotto' => $row['nome_prodotto'],
            'slug_prodotto' => $row['slug_prodotto'],
            'MAGENTO_ID' => $row['MAGENTO_ID'] ?? ''
        );

        
        foreach ($attributi as $nome_attributo => $dettagli_attributo) {

            $nome_attributo = normalizzaNomeColonna($nome_attributo);
           
            if (!in_array($nome_attributo, $attributi_header)) {
                $attributi_header[] = $nome_attributo;
            }
            $attributi_row[$nome_attributo] = $dettagli_attributo['value'] ?? $dettagli_attributo['name'] ?? '';
        }
        $attributi_rows[$row['id_prodotto']] = $attributi_row;
    }
} else {
    echo "Nessun risultato trovato per la prima query";
}

// Seconda query per ottenere informazioni aggiuntive
$sql2 = "SELECT
            t.name AS attribute_name,
tt.taxonomy AS attribute_taxonomy,
tr.object_id AS product_id,
p.post_title AS product_name,
p.post_name as slug_prodotto
FROM
ed2024_terms t
JOIN
ed2024_term_taxonomy tt ON t.term_id = tt.term_id
JOIN
ed2024_term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
JOIN
ed2024_posts p ON tr.object_id = p.ID
WHERE
p.post_type = 'product'
ORDER BY
p.ID, tt.taxonomy;";

$result2 = $conn->query($sql2);

// Elabora i risultati della seconda query
if ($result2->num_rows > 0) {
while($row2 = $result2->fetch_assoc()) {
$product_id = $row2['product_id'];
$attribute_taxonomy = $row2['attribute_taxonomy'];
$attribute_name = $row2['attribute_name'];


    // Aggiungi il nuovo header se non esiste
    if (!in_array($attribute_taxonomy, $attributi_header)) {
        $attributi_header[] = $attribute_taxonomy;
    }

    // Assicurati che l'array per questo prodotto esista
    if (!isset($attributi_rows[$product_id])) {
        $attributi_rows[$product_id] = array(
            'id_prodotto' => $product_id, 
            'nome_prodotto' => $row2['product_name'],
            'slug_prodotto' => $row2['slug_prodotto']
        );
    }

    // Aggiorna l'array dei dati del prodotto
    $attributi_rows[$product_id][$attribute_taxonomy] = $attribute_name;
}
} else {
    echo "Nessun risultato trovato per la seconda query";
    }
    
    // Creazione del file CSV
    $csvFileName = 'export-semi-pro-magento-id.csv';
    $csvFile = fopen($csvFileName, 'w');
    
    // Scrivi l'intestazione nel file CSV
    fputcsv($csvFile, $attributi_header);
    
    // Scrivi i valori degli attributi nel file CSV
    foreach ($attributi_rows as $product_id => $attributi_row) {
    $csvRow = array();
    foreach ($attributi_header as $header) {
    $csvRow[] = $attributi_row[$header] ?? '';
    }
    fputcsv($csvFile, $csvRow);
    }
    
    // Chiudi la connessione al database e il file CSV
    $conn->close();
    fclose($csvFile);
    
    echo "File CSV creato con successo: " . $csvFileName;

 
    
/*
// Prepara la query di inserimento
$columns = implode(', ', array_map(function($col) { return '`' . $col . '`'; }, $attributi_header));
$placeholders = implode(', ', array_fill(0, count($attributi_header), '?'));
$insertQuery = "INSERT INTO export_table ($columns) VALUES ($placeholders)";

$stmt = $conn->prepare($insertQuery);
if (!$stmt) {
    die("Errore nella preparazione della query: " . $conn->error);
}

// Divide $attributi_rows in lotti da 50 record
$lotti = array_chunk($attributi_rows, 50);

foreach ($lotti as $lotto) {
    foreach ($lotto as $attributi_row) {
        // Converti tutti i valori dell'array in stringa
        $values = array_map('strval', array_values($attributi_row));

        // Crea un array di tipi (tutti 's' per stringa)
        $types = str_repeat('s', count($values));

        // Lega i parametri alla query
        $stmt->bind_param($types, ...$values);

        // Esegui la query
        if (!$stmt->execute()) {
            echo "Errore durante l'inserimento dei dati: " . $stmt->error;
        }
    }
}

echo "Inserimento dei dati nella tabella riuscito con successo.";

// Chiudi lo statement e la connessione al database
//$stmt->close();
*/
//$conn->close();

    ?>
PHP, WordPress

Plugin Cart Flatsome

file woocommerce-cart-add-ons.php

cercare la linea <ul class=”products sfn-cart-addons”>

<ul class="products sfn-cart-addons row large-columns-4 medium-columns-3 small-columns-1 row-small">

 

AGGIUNGI AL FILE woocommerce-cart-add-ons.php (riga 71 circa)

//checkout page
add_action('woocommerce_after_checkout_form', array($this, 'cart_display_addons'), 20);

 

PHP

Fix Bridge – Velocità caricamento

  1. guarda bridgeshoot.com/shop / per prima cosa sistema i permessi con il file chmod

Create this files in your child theme: custom_js.js, custom_css.css, default_dynamic.js, style_dynamic.css. style_dynamic_responsive.css

3. View your site’s viewsource, open and copy custom_js.php, custom_css.php, default_dynamic.php, style_dynamic.php and style_dynamic_responsive.php content to it’s correspnding files created in child theme

4. Last step is to paste this code to your child theme’s functions.php file:

function qode_styles_child() {
    wp_deregister_style('style_dynamic');
    wp_register_style('style_dynamic', get_stylesheet_directory_uri() . '/style_dynamic.css');
    wp_enqueue_style('style_dynamic');

    wp_deregister_style('style_dynamic_responsive');
    wp_register_style('style_dynamic_responsive', get_stylesheet_directory_uri() .'/style_dynamic_responsive.css');
    wp_enqueue_style('style_dynamic_responsive');

    wp_deregister_style('custom_css');
    wp_register_style('custom_css', get_stylesheet_directory_uri() . '/custom_css.css');
    wp_enqueue_style('custom_css');
}

function qode_scripts_child() {
    wp_deregister_script('default_dynamic');
    wp_register_script('default_dynamic', get_stylesheet_directory_uri() . '/default_dynamic.js');
    wp_enqueue_style('default_dynamic', array(),false,true);

    wp_deregister_script('custom_js');
    wp_register_script('custom_js', get_stylesheet_directory_uri() . '/custom_js.js');
    wp_enqueue_style('custom_js', array(),false,true);
}

add_action( 'wp_enqueue_scripts', 'qode_styles_child', 11);
add_action( 'wp_enqueue_scripts', 'qode_scripts_child', 11);

 

javascript, jQuery, PHP, WordPress

Woocommerce Checkout – Configurazione campi

	function newFieldCheck(){
		
		//controlliamo di essere nella pagina giusta

		if (is_checkout()) {
	
		?>

			<script type="text/javascript">
				
			jQuery( document ).ready(function( $ ) {  
				
			// nascondo i campi di fatturazione
			
			$('#ragione_sociale_field').hide();
			$('#partita_iva_field').hide();
			$('#codice_destinatario_field').hide();
			$('#pec_field').hide();

				
			 // imposto un trigger sul campo di richiesta di fatturazione
			 	
			  $('#fattura_ricevuta').on('change', function (e) {
				  
// 				    var optionSelected = $("option:selected", this);
				    var valueSelected = this.value;
				    
				    if (valueSelected == 'SI'){
					    
					    $('.optional').hide();  //rimuovo la scritta opzionale sui campi di fatturazione
					    
					    	$('#ragione_sociale_field').show();
							$('#partita_iva_field').show();
							$('#codice_destinatario_field').show();
							$('#pec_field').show();		    			 
				    } 
				     
				     if (valueSelected == 'NO') {
					    
					    	$('#ragione_sociale_field').hide();
							$('#partita_iva_field').hide();
							$('#codice_destinatario_field').hide();
							$('#pec_field').hide();		    		    
				    }

				  
			  });				
				
			});  //end ready


			</script>
	
	
		<?php
			
		}
		
		
	} //end cpCheck



add_action('woocommerce_before_checkout_form', 'newFieldCheck');

 

 

 function validazioneFattura() {

		    $fattura = filter_input(INPUT_POST, 'fattura_ricevuta');
		    $ragione_sociale = filter_input(INPUT_POST, 'ragione_sociale');
   		    $piva = filter_input(INPUT_POST, 'partita_iva');
   		    $sdi = filter_input(INPUT_POST, 'codice_destinatario');
   		    $pec = filter_input(INPUT_POST, 'pec');
   		    $codice_fiscale = filter_input(INPUT_POST, 'codice_fiscale');

   			
   			if (strlen($codice_fiscale) != 16) {
		        wc_add_notice(__('<strong>Codice Fiscale:</strong> Errore, controlla i dati inseriti.'), 'error');
		    }

		
		    if ($fattura == 'SI' AND $ragione_sociale == '') {
		        wc_add_notice(__('<strong>Errore</strong>, devi inserire una Ragione Sociale'), 'error');
		    }
		    
		    // check partita iva  30/04/2019 - 16:30
		    
			if (($fattura == 'SI' AND strlen($piva) != 11) or ($fattura == 'Fattura' AND $piva == ''))  {
		        wc_add_notice(__('<strong>Partita IVA</strong>, Errore, controlla i dati inseriti'), 'error');
		    }
		    
		    // controllo fatturazione elettronica 24/02/2019 - 13:32
		    
		    if ($fattura == 'SI' AND $pec == '' AND $sdi == ''){
		        wc_add_notice(__('<strong>Errore</strong>, devi inserire un Codice Destinatario o un indirizzo PEC'), 'error');
		    }
			   
		    
		}
		
		add_action('woocommerce_checkout_process', 'validazioneFattura');

 

PHP

CHMOD FILE CARTELLE SU FTP SENZA ACCESSO SSH

<?php
header('Content-Type: text/plain');

  /**
  * Changes permissions on files and directories within $dir and dives recursively
  * into found subdirectories.
  */
  function chmod_r($dir, $dirPermissions, $filePermissions) {
      $dp = opendir($dir);
       while($file = readdir($dp)) {
         if (($file == ".") || ($file == ".."))
            continue;

        $fullPath = $dir."/".$file;

         if(is_dir($fullPath)) {
            echo('DIR:' . $fullPath . "\n");
            chmod($fullPath, $dirPermissions);
            chmod_r($fullPath, $dirPermissions, $filePermissions);
         } else {
            echo('FILE:' . $fullPath . "\n");
            chmod($fullPath, $filePermissions);
         }

       }
     closedir($dp);
  }

  chmod_r(dirname(__FILE__), 0755, 0644);
?>