class-wcml-gravityforms.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | class WCML_gravityforms implements \IWPML_Action { |
| 4 | |
| 5 | private $sitepress; |
| 6 | |
| 7 | private $woocommerce_wpml; |
| 8 | |
| 9 | public function __construct( SitePress $sitepress, woocommerce_wpml $woocommerce_wpml ) { |
| 10 | $this->sitepress = $sitepress; |
| 11 | $this->woocommerce_wpml = $woocommerce_wpml; |
| 12 | } |
| 13 | |
| 14 | public function add_hooks() { |
| 15 | add_action( 'wcml_after_duplicate_product_post_meta', [ $this, 'sync_gf_data' ], 10, 2 ); |
| 16 | } |
| 17 | |
| 18 | public function sync_gf_data( $original_product_id, $trnsl_product_id ) { |
| 19 | if ( $this->woocommerce_wpml->is_wpml_prior_4_2() ) { |
| 20 | $wcml_settings = get_option( '_wcml_settings' ); |
| 21 | $is_using_tm_editor = $wcml_settings['trnsl_interface']; |
| 22 | } else { |
| 23 | $is_using_tm_editor = WPML_TM_Post_Edit_TM_Editor_Mode::is_using_tm_editor( $this->sitepress, $original_product_id ); |
| 24 | } |
| 25 | |
| 26 | if ( $is_using_tm_editor ) { |
| 27 | $orig_gf = maybe_unserialize( get_post_meta( $original_product_id, '_gravity_form_data', true ) ); |
| 28 | |
| 29 | if ( $orig_gf ) { |
| 30 | $trnsl_gf = maybe_unserialize( get_post_meta( $trnsl_product_id, '_gravity_form_data', true ) ); |
| 31 | |
| 32 | if ( ! $trnsl_gf ) { |
| 33 | update_post_meta( $trnsl_product_id, '_gravity_form_data', $orig_gf ); |
| 34 | } else { |
| 35 | $trnsl_gf['id'] = $orig_gf['id']; |
| 36 | $trnsl_gf['display_title'] = $orig_gf['display_title']; |
| 37 | $trnsl_gf['display_description'] = $orig_gf['display_description']; |
| 38 | $trnsl_gf['disable_woocommerce_price'] = $orig_gf['disable_woocommerce_price']; |
| 39 | $trnsl_gf['disable_calculations'] = $orig_gf['disable_calculations']; |
| 40 | $trnsl_gf['disable_label_subtotal'] = $orig_gf['disable_label_subtotal']; |
| 41 | $trnsl_gf['disable_label_options'] = $orig_gf['disable_label_options']; |
| 42 | $trnsl_gf['disable_label_total'] = $orig_gf['disable_label_total']; |
| 43 | $trnsl_gf['disable_anchor'] = $orig_gf['disable_anchor']; |
| 44 | |
| 45 | update_post_meta( $trnsl_product_id, '_gravity_form_data', $trnsl_gf ); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 |