Forum Replies Created

Viewing 15 replies - 1 through 15 (of 21 total)
  • Thread Starter floi13

    (@floi13)

    Hi @torokzsofi

    Firstly my apologies for the late reaction. Wasn’t on here for a while.
    To answer your question; I first added the shortcode to the auction stuff in my template. After that I wrapped that shortcode into a div, like so…

    <div class="classofdiv">[add php shortcode here]</div>

    After that I edited my css for the auction like so…

    .classofdiv .auctionelement { add styling here }

    Like I said in a previous message, this might not be the most elegant way of doing things, but it solved my issue for the moment.

    Hope this helps, good luck!

    • This reply was modified 5 years ago by floi13.
    Thread Starter floi13

    (@floi13)

    Thanks for the reply, @payalrajyaguru
    Will have a look at this.

    Thread Starter floi13

    (@floi13)

    I’m not completely sure to be honest… give it a try, I would say.
    Worth mentioning is that in my case, it was purely based on a Contact Form 7 form, so didn’t do much if anything with database stuff.

    Thread Starter floi13

    (@floi13)

    Hi @jackbluehouse2019

    You should replace YOUR CPT NAME HERE with the name of your custom post type.

    Thread Starter floi13

    (@floi13)

    I’ve answered the first question myself. Just wrapped the auctions shortcode in a div and edited my css accordingly. Perhaps not the most elegant solution, but it does the trick.

    Question 2 however is something I can’t seem to find a fix for yet… anyone got any ideas?

    It seems that after I installed and activated the WP Mail SMTP plugin, the emails are being sent.
    A follow-up question that pops up in my mind is customizing the content of the email. At the moment it displays the product url, product name, bid value and product description.
    I would like to change this so that it displays something like User X made a bid of .. Euro’s on product Y.

    Owell, the plugins out-of-the-box functionality seems to work fine now… Would have liked a mention about a secondary email plugin though.

    • This reply was modified 5 years, 2 months ago by floi13.
    Thread Starter floi13

    (@floi13)

    Hi @bcworkz, thanks for you response(s). You’re correct: the current setup is a list of products and one form with radiobuttons for each product the user can choose.

    So if I follow you correctly, I should create a form per product?

    Thread Starter floi13

    (@floi13)

    Ow, my bad. I’ve created a github where I added my template-home.php and functions.php. Would be great if you could take a peak.

    The link is https://gist.github.com/floi5314/ac0f782cb86aeb934907c317d8660400

    Thread Starter floi13

    (@floi13)

    If you want I could give you the url and login if that would help clear some stuff? It’s just a development website, so no harm no foul.

    Thread Starter floi13

    (@floi13)

    The custom post type Offers I made in functions.php with the following code:

    function cptOffers() {
    	$labels = array(
    		'name' => _x('Offers', 'post type general name'),
    		'singular_name' => _x('offer', 'post type singular name'),
    		'edit_item' => __('Information about this offer'),
    		'all_items' => __('All offers'),
    		'view_item' => __('View offer'),
    		'search_items' => __('Search offers'),
    		'not_found' => __('No offers found'),
    		'not_found_in_trash' => __('No offers found in trash'),
    		'parent_item_colon' => '',
    		'menu_name' => 'Offers',
    	);
    	
    	$args = array(
    		'labels' => $labels,
    		'description' => 'All offers',
                    'public' => true,
                    'show_in_rest' => true,
    		'menu_icon' => 'dashicons-money-alt',
    		'supports' => array('title', 'thumbnail', 'custom-fields'),
    		'map_meta_cap' => true,
    		'capabilities' => array(
    			'create_posts'	=> 'do_not_allow'
    		),
    	);
    	
    	register_post_type('offers', $args);
    }
    add_action('init', 'cptOffers', 0);

    The ‘offer’ posts are create through form submit, with this piece of code:

    add_action('wpcf7_before_send_mail', 'save_application_form');
    function save_application_form($wpcf7){
    	global $wpdb;
      	$submission = WPCF7_Submission::get_instance();
    
      	$name 			= $_POST['your-name'];
      	$email 			= $_POST['email'];
      	$productchoice 	        = $_POST['radio-products'];
      	$offer 			= $_POST['offer'];
      	$comments 		= $_POST['message'];
    
      	$my_post = array(
        	'post_title' => $name,
        	'post_status' => 'publish',
        	'post_type' => 'offers',
        	'post_author' => 1,
      	);
      
    	$the_post_id = wp_insert_post($my_post);
      
    	update_post_meta($the_post_id, 'offer_made', $_POST['offer']);
    	update_post_meta($the_post_id, 'chosen_product', $_POST['products']);
    	update_post_meta($the_post_id, 'user_comments', $_POST['message']);
    }

    Correct me if I’m wrong, but I should add a hidden field to my form that holds the product id?

    Thread Starter floi13

    (@floi13)

    Could you provide a code example or maybe a snippet on which I can build upon?
    I tried finding it via Google, but I’m a little lost..

    Thread Starter floi13

    (@floi13)

    So, I’ve added a new acf Relationship field to the Product(s) post type. That gives me a dropdown for every product. But the available offer-posts must be selected by hand; this is not what I want.

    Question #1
    Is a relationship-field the way to go?

    Question #2
    If the answer on question #1 is yes, how do I proceed? Perhaps populating the dropdown with corresponding offers?

    Thread Starter floi13

    (@floi13)

    Thanks for your reply, @bcworkz
    Like you said I think the biggest problem I have is that there is no link between the cpts Offers and Products. Will have a look at that ‘meta_query’ and ‘meta_key’ you suggested.

    Thread Starter floi13

    (@floi13)

    I thought I had figured it out by getting the Offers cpt data via the REST api, but that didn’t work either. The url to the data I had in mind was something like //mydomain.test/wp-json/wp/v2/cpt-slug/$post->ID, but that would get the offer id; not the product id… So again two different items which should be combined.

    I’m thinking more and more what I’m trying to achieve can’t be done.

    Thread Starter floi13

    (@floi13)

    The thing that makes it a bit strange for me is that in my current setup I have two different custom post types. Reading up on meta data, the articles I’ve read so far all talk about the same post type…

    Thread Starter floi13

    (@floi13)

    Hi bcworkz,

    The Offers cpt is created with the following code:

    function cptOffers() {
    	$labels = array(
    		'name'					=> _x('Offers', 'post type general name'),
    		'singular_name'			=> _x('offer', 'post type singular name'),
    		//'add_new' 			=> _x('Add new', 'offer'),
    		//'add_new_item' 		=> __('Add new offer'),
    		'edit_item'				=> __('Information about this offer'),
    		//'new_item'			=> __('New offer'),
    		'all_items'				=> __('All offers'),
    		'view_item'				=> __('View offer'),
    		'search_items' 			=> __('Search offers'),
    		'not_found'				=> __('No offers found'),
    		'not_found_in_trash' 	=> __('No offers found in trash'),
    		'parent_item_colon' 	=> '',
    		'menu_name'				=> 'Offers'
    	);
    	
    	$args = array(
    		'labels'				=> $labels,
    		'description'			=> 'All offers',
    		'public'				=> true,
    		'menu_icon'				=> 'dashicons-money-alt',
    		'supports'				=> array('title', 'thumbnail', 'custom-fields'),
    		'has_archive'			=> true,
    		'map_meta_cap'			=> true,
    		'capabilities'			=> array(
    			'create_posts'	=> 'do_not_allow'
    		)
    	);
    	
    	register_post_type('offers', $args);
    }
    add_action('init', 'cptOffers', 0);

    The separate ‘posts’ are created via a form submit:

    add_action('wpcf7_before_send_mail', 'save_application_form');
    function save_application_form($wpcf7){
    	global $wpdb;
      	$submission = WPCF7_Submission::get_instance();
    
      	$name 			= $_POST['your-name'];
      	$email 			= $_POST['email'];
      	$productchoice 	= $_POST['radio-products'];
      	$offer 			= $_POST['offer'];
      	$comments 		= $_POST['message'];
    
      	$my_post = array(
        	'post_title' => $name,
        	'post_status' => 'publish',
        	'post_type' => 'offers',
        	'post_author' => 1,
      	);
      
    	$the_post_id = wp_insert_post($my_post);
      
    	update_post_meta($the_post_id, 'offer_made', $_POST['offer']);
    	update_post_meta($the_post_id, 'chosen_product', $_POST['products']);
    	update_post_meta($the_post_id, 'user_comments', $_POST['message']);
    }

    Every Offer post has 3 advanced custom fields, where ‘offer_made’ is the amount the user entered in the form.

Viewing 15 replies - 1 through 15 (of 21 total)