Skip to content

Commit d60efc1

Browse files
committed
Merge branch 'fix/profile-form-multistep-toggle' of https://github.com/arifulhoque7/wp-user-frontend into fix/profile-form-multistep-toggle
2 parents ab88de9 + e34634e commit d60efc1

File tree

3 files changed

+84
-23
lines changed

3 files changed

+84
-23
lines changed

includes/Admin/Forms/Post/Templates/Post_Form_Template_WooCommerce.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ public function after_update( $post_id, $form_id, $form_settings ) {
290290
public function handle_form_updates( $post_id, $form_id, $form_settings ) {
291291
$this->update_reviews( $post_id );
292292
$this->update_price( $post_id );
293-
$this->update_gallery_images( $post_id );
294293
$this->update_meta( $post_id );
295294
}
296295

@@ -305,8 +304,6 @@ public function update_reviews( $post_id ) {
305304
global $wpdb;
306305
$reviews = get_post_meta( $post_id, 'product_reviews', true );
307306
$status = ! empty( $reviews ) ? 'open' : 'closed';
308-
// wp_update_post( array( 'ID' => $post_id, 'comment_status' => $status ) );
309-
$comment_sql = "UPDATE {$wpdb->prefix}posts SET comment_status='{$status}' WHERE ID={$post_id} AND post_status='publish' AND post_type='product'";
310307
$wpdb->get_results( $wpdb->prepare( "UPDATE {$wpdb->prefix}posts SET comment_status=%s WHERE ID=%d AND post_status='publish' AND post_type='product'", $status, $post_id ) );
311308
}
312309

@@ -327,26 +324,6 @@ public function update_price( $post_id ) {
327324
}
328325
}
329326

330-
/**
331-
* Update image gallery
332-
*
333-
* @param int $post_id
334-
*
335-
* @return void
336-
*/
337-
public function update_gallery_images( $post_id ) {
338-
$images = get_post_meta( $post_id, '_product_image' );
339-
if ( ! empty( $images ) ) {
340-
if ( is_array( $images[0] ) ) {
341-
$images = $images[0];
342-
}
343-
if ( is_serialized( $images[0] ) ) {
344-
$images = maybe_unserialize( $images[0] );
345-
}
346-
update_post_meta( $post_id, '_product_image_gallery', implode( ',', $images ) );
347-
}
348-
}
349-
350327
/**
351328
* Fix for visibily not updating from frontend post
352329
*

includes/Integrations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Integrations {
2323
'WCMp' => 'WPUF_WCMp_Integration',
2424
'ACF' => 'WPUF_ACF_Compatibility',
2525
'Tribe__Events__Main' => 'Events_Calendar\Events_Calendar_Integration',
26+
'WooCommerce' => 'WPUF_WooCommerce_Gallery_Sync',
2627
];
2728

2829
public function __construct() {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace WeDevs\Wpuf\Integrations;
4+
5+
/**
6+
* WooCommerce Gallery Sync Integration
7+
*
8+
* Ensures product gallery images are properly synced between WPUF and WooCommerce
9+
*/
10+
class WPUF_WooCommerce_Gallery_Sync {
11+
12+
public function __construct() {
13+
// Hook into WPUF post insert/update actions
14+
add_action( 'wpuf_add_post_after_insert', [ $this, 'sync_product_gallery' ], 20, 4 );
15+
add_action( 'wpuf_edit_post_after_update', [ $this, 'sync_product_gallery' ], 20, 4 );
16+
17+
// Also hook into WordPress save_post for products
18+
add_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
19+
}
20+
21+
/**
22+
* Sync product gallery after WPUF form submission
23+
*
24+
* @param int $post_id
25+
* @param int $form_id
26+
* @param array $form_settings
27+
* @param array $meta_vars
28+
*/
29+
public function sync_product_gallery( $post_id, $form_id, $form_settings, $meta_vars = [] ) {
30+
// Only process if it's a product
31+
if ( get_post_type( $post_id ) !== 'product' ) {
32+
return;
33+
}
34+
35+
$this->sync_gallery_images( $post_id );
36+
}
37+
38+
/**
39+
* Sync gallery when product is saved
40+
*
41+
* @param int $post_id
42+
*/
43+
public function sync_gallery_on_save( $post_id ) {
44+
// Avoid infinite loops
45+
remove_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
46+
47+
$this->sync_gallery_images( $post_id );
48+
49+
// Re-add the action
50+
add_action( 'save_post_product', [ $this, 'sync_gallery_on_save' ], 20 );
51+
}
52+
53+
/**
54+
* Sync gallery images from _product_image to _product_image_gallery
55+
*
56+
* @param int $post_id
57+
*/
58+
private function sync_gallery_images( $post_id ) {
59+
$images = get_post_meta( $post_id, '_product_image', true );
60+
61+
if ( ! empty( $images ) ) {
62+
// Handle serialized data
63+
if ( is_string( $images ) && is_serialized( $images ) ) {
64+
$images = maybe_unserialize( $images );
65+
}
66+
67+
// Ensure we have an array
68+
if ( ! is_array( $images ) ) {
69+
$images = [ $images ];
70+
}
71+
72+
// Filter out empty values
73+
$images = array_filter( $images, function( $img ) {
74+
return ! empty( $img ) && ( is_numeric( $img ) || is_string( $img ) );
75+
});
76+
77+
// Update WooCommerce gallery meta
78+
if ( ! empty( $images ) ) {
79+
update_post_meta( $post_id, '_product_image_gallery', implode( ',', $images ) );
80+
}
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)