File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313global $ args , $ wpdb ;
1414
1515$ suffix = isset ( $ args [0 ] ) ? sanitize_key ( $ args [0 ] ) : (string ) time ();
16+ $ product_name = 'PPOM Quantity Matrix Product ' ;
1617
1718$ product_id = (int ) $ wpdb ->get_var (
1819 $ wpdb ->prepare (
1920 "SELECT ID FROM {$ wpdb ->posts } WHERE post_type = %s AND post_status = %s AND post_title = %s ORDER BY ID DESC LIMIT 1 " ,
2021 'product ' ,
2122 'publish ' ,
22- ' Product 1 '
23+ $ product_name
2324 )
2425);
2526
27+ if ( ! $ product_id ) {
28+ $ product = new WC_Product_Simple ();
29+ $ product ->set_name ( $ product_name );
30+ $ product ->set_status ( 'publish ' );
31+ $ product ->set_catalog_visibility ( 'visible ' );
32+ $ product ->set_regular_price ( '9.99 ' );
33+ $ product_id = $ product ->save ();
34+ }
35+
2636if ( ! $ product_id ) {
2737 echo wp_json_encode (
2838 array (
2939 'status ' => 'error ' ,
30- 'message ' => 'Product 1 not found ' ,
40+ 'message ' => 'Quantity matrix product could not be created ' ,
3141 )
3242 );
3343 exit ( 1 );
115125 'status ' => 'success ' ,
116126 'meta_id ' => $ meta_id ,
117127 'product_id ' => $ product_id ,
118- 'product_name ' => get_the_title ( $ product_id ) ,
128+ 'product_name ' => $ product_name ,
119129 'product_permalink ' => get_permalink ( $ product_id ),
120130 'quantity_field_id ' => 'seat_quantity_ ' . $ suffix ,
121131 )
You can’t perform that action at this time.
0 commit comments