Untitled
unknown
plain_text
a year ago
1.0 kB
22
Indexable
add_action( 'marketking_edit_product_after_tags', function($post){ ?> <div class="col-xxl-12 col-md-12 marketking_card_gal_cat_tags" style="background: white; padding:20px;border-radius: 4px;"> <h6>Password Protect Product</h6> <label>Password:</label> <input type="text" name="password" id="password" value="<?php echo $post->post_password; ?>"/> </div> <?php }); add_action('marketking_after_save_product', function($product_id, $vendor_id){ if (isset($_POST['password'])){ set_product_password($product_id, $_POST['password']); } }, 10, 2); function set_product_password($product_id, $password) { // Check if the product ID is valid and the product exists if ( ! $product_id || get_post_type( $product_id ) !== 'product' ) { return; } // Update the post to be password protected wp_update_post(array( 'ID' => $product_id, 'post_password' => $password, 'post_status' => 'publish' // Ensure the product is published )); }
Editor is loading...
Leave a Comment