Skip to content
Snippets Groups Projects
Select Git revision
  • c48871ff0813ed2064b68d89e35f6e5614718a3f
  • master default protected
  • devel
  • feature/add-escaping-to-templates
  • feature/add-priority-sorting
  • 3.3.0
  • 3.2.1
  • 3.2.0
  • 3.1.0
  • 3.0.0
  • 2.4.12
  • 2.4.11
  • 2.4.10
  • 2.4.9
  • 2.4.8
  • 2.4.7
  • 2.4.6
  • 2.4.5
  • 2.4.4
  • 2.4.2
  • 2.4.1
  • 2.4.0
  • 2.3.2
  • 2.3.1
  • 2.3
25 results

ProductSelectSerializer.php

Blame
  • ProductSelectSerializer.php 720 B
    <?php
    
    namespace WPDesk\Forms\Serializer;
    
    use WPDesk\Forms\Serializer;
    
    /**
     * When serializing product select data lets also write product names in keys.
     *
     * @package WPDesk\Forms\Serializer
     */
    class ProductSelectSerializer implements Serializer {
    	/**
    	 * @param $value
    	 */
    	public function serialize( $value ) {
    		$products_with_names = [];
    		if ( is_array( $value ) ) {
    			foreach ( $value as $product_id ) {
    				$product = wc_get_product( $product_id );
    				if ( $product ) {
    					$name                         = $product->get_formatted_name();
    					$products_with_names[ $name ] = $product_id;
    				}
    			}
    		}
    
    		return $products_with_names;
    	}
    
    	public function unserialize( $value ) {
    		return $value;
    	}
    
    }