• Skip to sidebar navigation
  • Skip to content

Bitbucket

  • More
    ProjectsRepositories
    • Help
      • Online help
      • Learn Git
      • Welcome to Bitbucket
      • Keyboard shortcuts
    • Log In
    Blackrock
    1. Blackrock

    main

    Public
    Actions
    • Clone

    Learn more about cloning repositories

    You have read-only access

    Navigation
    • Source
    • Commits
    • Branches
    • All Branches Graph
    • Graphs
    • Forks
    1. Blackrock
    2. main

    Source

    main/wp-content/plugins/woocommerce-multilingual/compatibility/class-wcml-variation-swatches-and-photos.php
    Артем ШиряевАртем Ширяев committed 554847ddcb906 Apr 2021
    Raw file
    Source viewDiff to previous
                    $translated_swatch_options = $this->translate_custom_attribute_value( $attribute_key, $attribute_value, $attribute_value_md5, $attribute_name_hash, $swatch_options, $translated_swatch_options, $original_product_id, $translated_product_id );
     
    1
    <?php
    2
    ​
    3
    /**
    4
     * Compatibility class for Variation Swatches and Photos plugin
    5
     */
    6
    class WCML_Variation_Swatches_And_Photos {
    7
    ​
    8
        /** @var woocommerce_wpml */
    9
        private $woocommerce_wpml;
    10
    ​
    11
        public function __construct( woocommerce_wpml $woocommerce_wpml ) {
    12
            $this->woocommerce_wpml = $woocommerce_wpml;
    13
        }
    14
    ​
    15
        public function add_hooks() {
    16
            add_action( 'wcml_after_sync_product_data', [ $this, 'sync_variation_swatches_and_photos' ], 10, 3 );
    17
        }
    18
    ​
    19
        /**
    20
         * Synchronize Variation Swatches and Photos
    21
         *
    22
         * @param int    $original_product_id Original product ID.
    23
         * @param int    $translated_product_id Translated product ID.
    24
         * @param string $language
    25
         */
    26
        public function sync_variation_swatches_and_photos( $original_product_id, $translated_product_id, $language ) {
    27
    ​
    28
            $swatch_options            = maybe_unserialize( get_post_meta( $original_product_id, '_swatch_type_options', true ) );
    29
            $translated_swatch_options = $swatch_options;
    30
    ​
    31
            if ( $swatch_options ) {
    32
                $original_product_attributes = $this->woocommerce_wpml->attributes->get_product_attributes( $original_product_id );
    33
    ​
    34
                wpml_collect( $original_product_attributes )->each(
    35
                    function ( $attribute, $attribute_key ) use ( $swatch_options, &$translated_swatch_options, $language, $original_product_id, $translated_product_id ) {
    36
                        $attribute_name_hash = md5( sanitize_title( $attribute['name'] ) );
    37
                        if ( $this->woocommerce_wpml->attributes->is_a_taxonomy( $attribute ) ) {
    38
                            $translated_swatch_options = $this->translate_taxonomy_attributes( $attribute_key, $attribute_name_hash, $swatch_options, $translated_swatch_options, $language );
    39
                        } else {
    40
                            $translated_swatch_options = $this->translate_custom_attributes( $attribute_key, $attribute, $attribute_name_hash, $swatch_options, $translated_swatch_options, $original_product_id, $translated_product_id );
    41
                        }
    42
                    }
    43
                );
    44
    ​
    45
            }
    46
    ​
    47
            update_post_meta( $translated_product_id, '_swatch_type_options', $translated_swatch_options );
    48
        }
    49
    ​
    50
        private function translate_taxonomy_attributes( $taxonomy, $attribute_name_hash, $swatch_options, $translated_swatch_options, $language ) {
    51
            $attribute_terms = get_terms( [ 'taxonomy' => $taxonomy ] );
    52
    ​
    53
            wpml_collect( $attribute_terms )->each(
    54
                function ( $term ) use ( $taxonomy, $attribute_name_hash, $swatch_options, &$translated_swatch_options, $language ) {
    55
                    $attribute_term_slug_md5   = md5( $term->slug );
    56
                    $translated_swatch_options = $this->translate_taxonomy_term( $term, $attribute_term_slug_md5, $taxonomy, $attribute_name_hash, $swatch_options, $translated_swatch_options, $language );
    57
                }
    58
            );
    59
    ​
    60
            return $translated_swatch_options;
    61
        }
    62
    ​
    63
        private function translate_taxonomy_term( $term, $attribute_term_slug_md5, $taxonomy, $attribute_name_hash, $swatch_options, $translated_swatch_options, $language ) {
    • Git repository management for enterprise teams powered by Atlassian Bitbucket
    • Atlassian Bitbucket v5.10.1
    • Documentation
    • Contact Support
    • Request a feature
    • About
    • Contact Atlassian
    Atlassian

    Everything looks good. Well let you know here if theres anything you should know about.